2016-07-24 12 views
3

私は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がそれを使用しています。

答えて

1

私はWebSocket packet is sent to us by a client、メッセージがかかる一旦send_freeは、他の言葉ではmessage.reply_channel ...

を持っていない

Channel('send-free').send({'message': 'your message'}) 

...あなたはこのようなあなたのビューから"send-free"を呼び出していると仮定それからのreply_channel属性。それはクライアントに返信するメッセージに使用されます...(フロントエンドに)

本当にメッセージを送信したいのですか?消費者を使用して再度送信してください...

+0

はい正しいです。私はあなたがそれを記述した方法でsend-freeと呼んでいます。しかし、私はプロセスを繰り返すことで何を意味するのか分かりません。 – dowu

+0

@dowu 'Channel(" cons ")send(dict)'を繰り返し、また私は答えを編集しました.. –

+0

これで 'message.reply_channel 'の代わりに' Channel( "otherchanel")send(dict)もう一度送りますか? "otherchannel"は関数にリンクされているとは思われないので、同じ問題が残っていますか? – dowu

関連する問題