You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

consumers.py 527B

1234567891011121314151617181920212223
  1. # chat/consumers.py
  2. import json
  3. from channels.generic.websocket import WebsocketConsumer
  4. class ChatConsumer(WebsocketConsumer):
  5. def connect(self):
  6. self.accept()
  7. def disconnect(self, close_code):
  8. pass
  9. def receive(self, text_data):
  10. text_data_json = json.loads(text_data)
  11. message = text_data_json['message']
  12. self.send(text_data=json.dumps({
  13. 'message': message
  14. }))
  15. self.send(text_data=json.dumps({
  16. 'message': {"abc":123}
  17. }))