R
Railway•2y ago
Tonquin

Alternative to gunicorn for an asgi django app

Hey everyone, I am attempting to host a personal project I have been working on to learn Django/Websockets. I am using Django Channels. I have run into quite a few issues with hosting the app on railway and currently it seems to be that I am trying to host an asgi application where as most of the hosting tutorials I have looked at have been using a wsgi application. Does anyone have any advice for hosting an asgi application and what to use instead of gunicorn? I am a bit confused as to what gunicorn actually does to be honest. Any help or info would be much appreciated 🙂
Solution:
actually I think this is the correct syntax
daphne -b 0.0.0.0 -p $PORT backend.asgi:application
daphne -b 0.0.0.0 -p $PORT backend.asgi:application
...
Jump to solution
25 Replies
Percy
Percy•2y ago
Project ID: 7c4860ab-7860-4ab6-bbee-a6b54838c725
Tonquin
TonquinOP•2y ago
7c4860ab-7860-4ab6-bbee-a6b54838c725
Brody
Brody•2y ago
you'll likely want daphne for django
MantisInABox
MantisInABox•2y ago
Gunicorn is a production capable server for python. That’s why it’s used You can use daphne like Brody said as well
Brody
Brody•2y ago
and I was even gonna tag you in lol
MantisInABox
MantisInABox•2y ago
Hahaha, I just happened to be on my phone when the post came through
MantisInABox
MantisInABox•2y ago
You can look at the Django template to see how things are configured also https://github.com/railwayapp-templates/django
GitHub
GitHub - railwayapp-templates/django: 1-Click Django on Railway
1-Click Django on Railway. Contribute to railwayapp-templates/django development by creating an account on GitHub.
Tonquin
TonquinOP•2y ago
I am using daphne actually, I followed the django channels tutorial from here (https://channels.readthedocs.io/en/stable/tutorial/part_1.html). I changed my railway.json to include this line: "python manage.py migrate && python manage.py && daphne backend.asgi" instead and I will see how that goes. thanks for the quick replies 🙂
MantisInABox
MantisInABox•2y ago
Awesome! Report back for sure
Tonquin
TonquinOP•2y ago
I have been looking back and forth at the template and it's been super helpful, just struggling a bit to figure out what to change for asgi vs wsgi
Brody
Brody•2y ago
Daphne may or may not need to be told to listen on host 0.0.0.0 and PORT
MantisInABox
MantisInABox•2y ago
Really, you should only have to change which you are pointing to depending on the server you use
Brody
Brody•2y ago
yes it does need to be told use this instead daphne -b 0.0.0.0 -p $PORT backend.asgi
Tonquin
TonquinOP•2y ago
I got this error from my last fix: #### Traceback (most recent call last): File "/opt/venv/bin/daphne", line 8, in <module> sys.exit(CommandLineInterface.entrypoint()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/venv/lib/python3.11/site-packages/daphne/cli.py", line 171, in entrypoint cls().run(sys.argv[1:]) File "/opt/venv/lib/python3.11/site-packages/daphne/cli.py", line 233, in run application = import_by_path(args.application) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/venv/lib/python3.11/site-packages/daphne/utils.py", line 11, in import_by_path module_path, object_path = path.split(":", 1) ^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: not enough values to unpack (expected 2, got 1) #### not sure if it has anything to do with your suggestion but will try to add that in
Solution
Brody
Brody•2y ago
actually I think this is the correct syntax
daphne -b 0.0.0.0 -p $PORT backend.asgi:application
daphne -b 0.0.0.0 -p $PORT backend.asgi:application
Tonquin
TonquinOP•2y ago
Yep that seems to be correct! Got rid of the previous errors and seems to be mostly working now, just a new error where I maybe have to install another dependency or something
Tonquin
TonquinOP•2y ago
Brody
Brody•2y ago
do you have an endpoint for the root registered?
Tonquin
TonquinOP•2y ago
Not 100% sure I understand, so I assume not The build was successful and I can connect to the server if thats what you mean. The link is https://wordle-with-friends-backend-production.up.railway.app/
Brody
Brody•2y ago
okay then all is good looks like it works for me, at least the /games endpoint fetch request does
Tonquin
TonquinOP•2y ago
okay amazing! there seems to be an issue with connecting to the admin site but I think I just have to add something like: CSRF_TRUSTED_ORIGINS = ['https://your-domain.com'] to my settings.py
Brody
Brody•2y ago
I forget if you include the https:// part, so read the docs on that, but yeah you got the right idea
Tonquin
TonquinOP•2y ago
It worked with the https:// included! Okay looks like I made a lot of good progress there! Thanks again for your help 🙂
Brody
Brody•2y ago
no problem!
MantisInABox
MantisInABox•2y ago
Awesome
Want results from more Discord servers?
Add your server