new _backend

This commit is contained in:
2025-01-07 14:21:46 +08:00
parent 87c87aa328
commit 1fd031d6e6
59 changed files with 10633 additions and 0 deletions

25
_backend/consumers.py Normal file
View File

@@ -0,0 +1,25 @@
# your_app_name/consumers.py
import json
from channels.generic.websocket import AsyncWebsocketConsumer
class ChatConsumer(AsyncWebsocketConsumer):
async def connect(self):
await self.accept()
async def disconnect(self, close_code):
pass
async def receive(self, text_data):
#text_data_json = json.loads(text_data)
#message = text_data_json['message']
# 在这里处理接收到的消息
print(f"Received message: {text_data}")
# 发送消息回客户端
response_text = {
'message': f'You said: {text_data}'
}
await self.send(text_data=json.dumps(response_text))