django-channels - group send不调用“type”中定义的函数

5kgi1eie  于 2023-03-13  发布在  Go
关注(0)|答案(1)|浏览(131)

我有这个消费者:

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语句永远不会执行,我不明白为什么。
为什么会这样呢?
谢谢。

nafvub8i

nafvub8i1#

它不起作用,因为我覆盖了self.channel_name。

相关问题