小编paz*_*s10的帖子

Django频道 - 回声示例不起作用

我正在按照文档站点中的说明进行操作,但我遇到了echo示例,websocket已正确创建并且已连接到服务器但是当我向服务器发送任何内容时,我没有得到任何响应(在示例中)说我应该看到一个警告窗口,其中包含我发送到套接字的相同消息,但我没有,虽然我已经更改了console.log的警报,但仍然),我做错了什么?

settings.py中:

INSTALLED_APPS = {
    ...
    'channels',
    'myapp',
    ...
} 

...
# Channels settings
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "asgiref.inmemory.ChannelLayer",
        "ROUTING": "myapp.routing.channel_routing",
    },
}
Run Code Online (Sandbox Code Playgroud)

routing.py中:

from channels.routing import route
from myapp.consumers import *

channel_routing = [
    route("websocket.receive", ws_receive),
]
Run Code Online (Sandbox Code Playgroud)

consumers.py中:

def ws_receive(message):
    # ASGI WebSocket packet-received and send-packet message types
    # both have a "text" key for their textual data.
    message.reply_channel.send({
        "text": message.content['text'],
    })
Run Code Online (Sandbox Code Playgroud)

在asgi.py

import os
from channels.asgi import get_channel_layer …
Run Code Online (Sandbox Code Playgroud)

javascript python django websocket django-channels

10
推荐指数
1
解决办法
1515
查看次数

TypeError:无法读取未定义的属性(读取“集合”)-Vuejs 和 Firebase

我正在尝试开发一个包含任务的日历。我正在尝试使用 firebase,但它不断给出错误,表示它不理解“collection()”属性。我已经研究了很多东西,尝试用其他方法来做,但我什么也没得到。如果我不这样做,我可以注册,但用“集合”读取数据,不行。详细信息我正在使用 firebase 版本 9

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'collection')
Run Code Online (Sandbox Code Playgroud)

我不知道还能做什么,有人可以帮助我吗?整个脚本如下。

脚本

export default {
  data: () => ({
    today: new Date().toISOString().substr(0, 10),
    focus: new Date().toISOString().substr(0, 10),
    type: 'month',
    typeToLabel: {
      month: 'Month',
      week: 'Week',
      day: 'Day',
      '4day': '4 Days',
    },
    name: null,
    details: null,
    start: null,
    end: null,
    color: '#1976D2', // default event color
    currentlyEditing: null,
    selectedEvent: {},
    selectedElement: null,
    selectedOpen: false,
    events: [],
    dialog: false
  }),
  mounted () {
    this.getEvents()
  },
  computed: …
Run Code Online (Sandbox Code Playgroud)

javascript firebase vue.js vuejs2 google-cloud-firestore

5
推荐指数
1
解决办法
2万
查看次数

Django累积总和或运行总和

我正在尝试制作一份党派账簿。哪些详细信息将按日期搜索结果显示。我有一个列名称平衡,它将按日期搜索显示累积数据。我想查看表中的cumbalance列取决于余额列。

               --------------------------------------
               amount  payment   balance     CumBalance
               --------------------------------------  
                 10       5         5          5
                 20       5         15        20
                 10       15        -5        15
Run Code Online (Sandbox Code Playgroud)

我的看法:

               --------------------------------------
               amount  payment   balance     CumBalance
               --------------------------------------  
                 10       5         5          5
                 20       5         15        20
                 10       15        -5        15
Run Code Online (Sandbox Code Playgroud)

我也尝试过.aggregate(Sum('balance'))

我的模型:

def partyDetails(request,pk):
    form = DateRangeForm()
    if request.method == 'POST':
        form = DateRangeForm(request.POST or None)
          if form.is_valid():
           cumulative_balance = PurchasePayment.objects.all()
                               .filter(vendor=pk,date__range= 
                               (form.cleaned_data['start_date'],
                                form.cleaned_data['end_date']))
                                .annotate(cumbalance =Sum('balance'))
         else:
           return redirect('party_ledger')
     return render(request, 'purchase/party_details.html', 
                             {'dateform':form, 
                             'cumbal':cumulative_balance,'name':pk})
Run Code Online (Sandbox Code Playgroud)

python django postgresql

2
推荐指数
1
解决办法
710
查看次数