私はDjangoのチャンネルの周りに頭を上げようとしています。私のメッセージを私のwebsocketに送ることができません。django channels message.reply_channel no attribute send
はここにある私の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がそれを使用しています。
はい正しいです。私はあなたがそれを記述した方法でsend-freeと呼んでいます。しかし、私はプロセスを繰り返すことで何を意味するのか分かりません。 – dowu
@dowu 'Channel(" cons ")send(dict)'を繰り返し、また私は答えを編集しました.. –
これで 'message.reply_channel 'の代わりに' Channel( "otherchanel")send(dict)もう一度送りますか? "otherchannel"は関数にリンクされているとは思われないので、同じ問題が残っていますか? – dowu