import json from update.views import cinema_update_status from channels.generic.websocket import WebsocketConsumer 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('你发了啥') else: if text_data.startswith('ip:'): ip = text_data.replace('ip:', '') self.send(json.dumps(cinema_update_status.get(ip, None))) else: self.send(text_data)