调用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$"),