first update

This commit is contained in:
2024-12-30 17:01:16 +08:00
parent 728c0a0ede
commit 6e8b0a7f15
82 changed files with 11379 additions and 2 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))