Problem With Django Channels in Production

Hi all. I'm finding an issue with django channels in production. I'm running my django using docker. Everything works fine locally with environment variables set those same as production. But in production im getting the error --- Not Found: /ws/restaurant/11/orders/ I dont get this error locally even though im connected those of railway
Solution:
you need to do a few things - - set this as your CMD line in your dockerfile - CMD ["gunicorn", "cravingConnect.asgi", "-k", "uvicorn.workers.UvicornWorker"] - add uvicorn to your requirements.txt file - uvicorn==0.30.6 - remove your start command from your service settings....
Jump to solution
22 Replies
Percy
Percy3mo ago
Project ID: 05ab52eb-b35d-4e9b-8c08-a46da8c240ac
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
05ab52eb-b35d-4e9b-8c08-a46da8c240ac
Brody
Brody3mo ago
when you develop locally what command do you use to start your app
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
python manage.py runserver localhost:8000
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
this is my docker for prod
No description
Brody
Brody3mo ago
gotcha, that is s dev server and it supports websockets, in production you are using gunicorn that doesnt support websockets
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
so what am i supposed to do can u pls help
Brody
Brody3mo ago
you need to run it with a uvicorn worker instead of gunicorn's sync workers
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
so should i modify my dockerfile or do some changes in railway itself ?
Solution
Brody
Brody3mo ago
you need to do a few things - - set this as your CMD line in your dockerfile - CMD ["gunicorn", "cravingConnect.asgi", "-k", "uvicorn.workers.UvicornWorker"] - add uvicorn to your requirements.txt file - uvicorn==0.30.6 - remove your start command from your service settings.
Brody
Brody3mo ago
have you made the changes from point 1 & 2?
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
yes
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
GitHub
GitHub - midhun98/CRAVING-CONNECT: APIs for Craving Connect
APIs for Craving Connect. Contribute to midhun98/CRAVING-CONNECT development by creating an account on GitHub.
Brody
Brody3mo ago
okay do a ctrl / cmd + k -> deploy latest commit you need gunicorn in your requirements.txt file too
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
ok
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
i mean i did the 3rd step also but still getting err
No description
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
yes it worked thanks a lot
Brody
Brody3mo ago
no problem!
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
pip install uvicorn[standard] had to install this also
Brody
Brody3mo ago
sounds good
MIGHTY_MIDHUN
MIGHTY_MIDHUNOP3mo ago
https://medium.com/@midhunskani/django-channels-with-redis-deployment-on-railway-app-860e6d657d2a I have written a blog on deploying to railway.app based on the changes. Hope this would be helpful to others facing the same issue.
Medium
Django Channels With Redis Deployment on railway.app
Hi everyone. In this blog I will teach you how to implement Django Channels with Redis in production. For this I will be using a platform…
Brody
Brody3mo ago
awsome, very cool!
Want results from more Discord servers?
Add your server