3
我一直試圖讓我的頭繞着Django的頻道,我無法讓我的消息被髮送到我的websocket。django頻道message.reply_channel沒有屬性發送
這裏是我的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就像我嘗試使用它。
是的你是正確的我打電話發送免費的方式,你描述它。但是,我不明白重複這個過程的意思。 – dowu
@dowu重複'Channel(「cons」)。send(dict)'並且我編輯了答案.. –
好吧,我叫'Channel(「otherchanel」)。send(dict)'而不是'message.reply_channel。再次發送?是不是「otherchannel」應該被鏈接到一個函數,所以我堅持相同的問題? – dowu