Problem With Django Channels in Production
midhun98
HOBBYOP

2 years ago

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

22 Replies

midhun98
HOBBYOP

2 years ago

05ab52eb-b35d-4e9b-8c08-a46da8c240ac


2 years ago

when you develop locally what command do you use to start your app


midhun98
HOBBYOP

2 years ago

python manage.py runserver localhost:8000


midhun98
HOBBYOP

2 years ago

this is my docker for prod

1283446687704158200


2 years ago

gotcha, that is s dev server and it supports websockets, in production you are using gunicorn that doesnt support websockets


midhun98
HOBBYOP

2 years ago

so what am i supposed to do can u pls help


2 years ago

you need to run it with a uvicorn worker instead of gunicorn's sync workers


midhun98
HOBBYOP

2 years ago

so should i modify my dockerfile or do some changes in railway itself ?


2 years 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.


2 years ago

have you made the changes from point 1 & 2?


midhun98
HOBBYOP

2 years ago

yes



2 years ago

okay do a ctrl / cmd + k -> deploy latest commit


2 years ago

you need gunicorn in your requirements.txt file too


midhun98
HOBBYOP

2 years ago

ok


midhun98
HOBBYOP

2 years ago

i mean i did the 3rd step also but still getting err

1283452124767977500


midhun98
HOBBYOP

2 years ago

yes it worked thanks a lot


2 years ago

no problem!


midhun98
HOBBYOP

2 years ago

pip install uvicorn[standard]

had to install this also


2 years ago

sounds good


midhun98
HOBBYOP

2 years 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.


2 years ago

awsome, very cool!


Loading...