from channels.generic.websocket import WebsocketConsumer import json class UpdateConsumer(WebsocketConsumer): def connect(self): self.accept() self.send('你已经连接成功') def receive(self, text_data=None, bytes_data=None): if text_data is None: self.send('你发了啥') if text_data == 'update': self.send(json.dumps({'code': '111'})) if text_data == 'close': self.send('白白') self.close() self.disconnect('500') else: self.send(f'你收到的消息是{text_data}')