1. WebSocket: 2. Django-socketio: html <script src="https://cdn.socket.io/4.2.0/socket.io.min.js"></script> script const socket = io.connect('http://localhost:8000'); python INSTALLED_APPS = [ ... 'django_socketio', ] MIDDLEWARE = [ ... 'django_socketio.middleware.SocketIOHandler', ] STATIC_URL = '/static/' SOCKETIO_PORT = 8000 python from django_socketio import broadcast, broadcast_channel, NoSocket def my_view(request): if request.is_ajax(): message = request.POST.get('message') ... broadcast(message) else: ...


上一篇:
下一篇:
切换中文