我一直在努力了解Django的频道,但我无法将我的信息发送到我的websocket。在
这是我的consumers.py
import logging
from django.contrib.sites.models import Site
from django.utils import timezone
from channels import Group
from .models import *
import json
def send_free(message):
try:
pi = PInformation.objects.get(
pk=message.content.get('pk'),
)
except Parkplatzinformationen.DoesNotExist:
logging.error("PI not found!")
return
try:
message.reply_channel.send({
"text": 1,
})
except:
logging.exception('Problem sending %s' % (pi.name))
我的routing.py
我得到错误AttributeError: 'NoneType' object has no attribute 'send'
。但是它确实得到了PInformation对象,所以它确实工作了一点。我在保存对象后马上调用它。在
你能给我一些提示吗?The Getting Started guide像我一样使用它。在
我假设您是这样从您的角度调用
"send-free"
。。。在那么}。。。在
send_free
没有{换句话说,一旦
WebSocket packet is sent to us by a client
,那么消息就会从中获取reply_channel
属性。它将用于向客户端回复消息。。。(可能对前台说)所以你真的想发个信。。。?然后再次使用消费者发送。。。在
相关问题 更多 >
编程相关推荐