Django 3 and Daphne deploy
See original GitHub issueHi,
I’m trying to implement a simple socket emit with Django 3 and Daphne, but for some reason the event emited isn’t never captured by the client. Here is my code
asgi.py
import os
import socketio
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'eleicoes.settings')
sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins='*')
application = socketio.ASGIApp(sio, get_asgi_application())
views.py
from eleicoes.asgi import sio
# other code
print('emit vote event', sio)
sio.emit('user', UserSerializer(instance=request.user).data)
# other code
It simples doesn’t work. I think I followed the documentation in this matter but I can’t find anything with this specific setup (django 3 and daphne)
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How to use Django with Daphne
When Daphne is installed, a daphne command is available which starts the Daphne server process. At its simplest, Daphne needs to be called...
Read more >Deploying — Channels 4.0.0 documentation
Channels (ASGI) applications deploy similarly to WSGI applications - you load them into a server, like Daphne, and you can scale the number...
Read more >Configuring ASGI Django Application using Daphne and ...
My WSGI Django Application was already deployed using Gunicorn server and Nginx was used to serve static files and provide proxy to gunicorn ......
Read more >Django deployment with Daphne - nginx - Stack Overflow
I want to deploy my Django app (Rest API + React on frontend) on AWS. I use nginx, gunicorn (for http handling) and...
Read more >Daphne - Django Channels HTTP/WebSocket server - GitHub
Daphne is a HTTP, HTTP2 and WebSocket protocol server for ASGI and ASGI-HTTP, developed to power Django Channels. It supports automatic negotiation of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I suggest you remove
cors_allowed_origins='*'
. This is basically allowing anybody to connect to your server, and can open the door to CSRF attacks. My recommendation is that you explicitly name the allowed origins instead.I honestly don’t know how to thank you. Apparently the problem was I had added the wrong
async_mode
onsocketio.Server
. I’ll put the correct configuration down here to whoever this may help in the future.myapp.wsgi
uWSGI command line
uwsgi --http :8000 --gevent 1000 --http-websockets --master --module myapp.wsgi:application