【发布时间】:2016-07-24 17:13:20
【问题描述】:
我一直在尝试了解 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
from channels.routing import route
from RESTAPI.consumers import send_free
channel_routing = [
route('send-free',send_free),
]
我收到错误 AttributeError: 'NoneType' object has no attribute 'send'。然而,它确实获得了 PInformation 对象,因此它确实“有点”工作。我在保存对象后立即调用它。
你能给我一些提示吗? The Getting Started guide 使用它就像我尝试的那样。
【问题讨论】:
标签: python django django-channels