2016-07-24 2 views
3

장고 채널에서 머리를 쓰려고 노력 중이며 내 메시지를 내 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), 
] 

I 오류 AttributeError: 'NoneType' object has no attribute 'send' 받고 있어요. 그러나 PInformation 개체를 가져 와서 "비트"작업을 수행합니다. 나는 물건을 저장 한 직후에 그것을 부르고있다.

몇 가지 힌트를 제공해 주시겠습니까? 내가하려고하는 것처럼 The Getting Started guide이 그것을 사용합니다. WebSocket packet is sent to us by a client 다음 메시지가 소요 일단 당신이이 같은보기에서 "send-free"를 호출한다고 가정

답변

1

...

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

그런 다음 send_free 다른 단어에서 message.reply_channel ...

이 없습니다 그것으로부터 reply_channel 속성. 그 메시지를 클라이언트에 회신하는 데 사용할 수 있습니다 ... (프론트 엔드 어쩌면)

그럼 정말 메시지를 보내시겠습니까 ...? 그런 다음 다시 소비자를 사용하여 보내십시오.

+0

예 맞습니다. 나는 당신이 설명 한대로 send-free라고 부릅니다. 그러나 나는 그 과정을 반복 함으로 당신이 의미하는 바를 얻지 못한다. – dowu

+0

@dowu'Channel ("cons"). send (dict)'를 반복하고 또한 대답을 편집했습니다 .. –

+0

좋아요, 그래서 저는'message.reply_channel '대신'Channel ("otherchanel") send (dict)를 호출합니다. 다시 보내? "otherchannel"이 함수에 연결되어 있지 않아서 같은 문제가 붙어 있습니까? – dowu