我有这个消费者:
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}))
由于某种原因,print语句永远不会执行,我不明白为什么。
为什么会这样呢?
谢谢。
1条答案
按热度按时间nafvub8i1#
它不起作用,因为我覆盖了self.channel_name。