英文:
django-channels - group send does not call the function defined in "type"
问题
我有这个Consumer:
class TableConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.table_name = f'table_test'
self.channel_name = f'channel_test'
await self.accept()
await self.channel_layer.group_add(
self.table_name, self.channel_name
)
await self.manage_new_game_video()
async def manage_new_game_video(self):
await this.channel_layer.group_send(
self.table_name, {"type": "chat_message", "message": "message"}
)
# Receive message from room group
async def chat_message(self, event):
print("test")
message = event["message"]
# Send message to WebSocket
await self.send(text_data=json.dumps({"message": message}))
由于某种原因,print语句从未被执行,我不明白为什么。
为什么会发生这种情况?
谢谢。
英文:
I have this Consumer:
class TableConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.table_name = f'table_test'
self.channel_name = f'channel_test'
await self.accept()
await self.channel_layer.group_add(
self.table_name, self.channel_name
)
await self.manage_new_game_video()
async def manage_new_game_video(self):
await self.channel_layer.group_send(
self.table_name, {"type": "chat_message", "message": "message"}
)
# Receive message from room group
async def chat_message(self, event):
print("test")
message = event["message"]
# Send message to WebSocket
await self.send(text_data=json.dumps({"message": message}))
for some reason, the print statement is never executed and I don't understand why.
Why can that happen?
Thanks.
答案1
得分: 1
因为我重写了self.channel_name,所以它不起作用。
英文:
It is not working because I overrided self.channel_name.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论