Django-channel尝试在通道上发送消息返回错误发送属性不存在

时间:2017-05-19 09:09:17

标签: django django-channels

调用django-channel对象时,我收到以下错误

Channel("websocket.receive").send({
    "room": message.channel_session['room'],
    "message": message['text'],
})

AttributeError: 'Channel' object has no attribute 'send'

这是消费者功能。函数内的打印消息正在打印

def ws_receive_in_music_channel(message,pk):

   print("received a message")
   payload = message.content['text']


   Channel("websocket.receive").send({
     "room": message.channel_session['room'],
     "message": message['text'],
   })

routing.py

channel_routing = [

route("websocket.connect",ws_connect, path=r'^/mychannels/$'),
route("websocket.connect",ws_connect_music_channel, path=r'^/mychannels/(?P<pk>\S+)/$'),

route("websocket.disconnect",ws_disconnect,path=r'^/mychannels/$'),
route("websocket.disconnect",ws_disconnect_music_channel,path=r'^/mychannels/(?P<pk>\S+)/$'),

route("websocket.receive",ws_receive,path=r'^/mychannels/$'),

route("websocket.receive",ws_receive_in_music_channel, path=r'^/mychannels/(?P<pk>\S+)/$'),

#route for share song in a channel
route("music_channel.share_song",share_song,command="^share$"),

0 个答案:

没有答案