Deploy django-channels to render.com

I implemented django-channels and daphne, and it works locally based on this tutorial :
Tutorial — Channels 3.0.3 documentation

However, I have difficulties to deploy the application to render based on these guidelines
Deploying — Channels 3.0.3 documentation

I have set the following start command

daphne my_app_name.asgi:application

Here is asgi.py

import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_app_name.settings")
django.setup()
from channels.http import AsgiHandler
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import chat.routing
application = ProtocolTypeRouter({
    "http": AsgiHandler(),
     "websocket": AuthMiddlewareStack(
         URLRouter(
            chat.routing.websocket_urlpatterns
        )
    ),
})

And here is the error returned when I try to deploy :

Mar 12 10:50:39 AM  2021-03-12 10:50:39,398 INFO     Starting server at tcp:port=8000:interface=127.0.0.1
Mar 12 10:50:39 AM  2021-03-12 10:50:39,399 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
Mar 12 10:50:39 AM  2021-03-12 10:50:39,399 INFO     Configuring endpoint tcp:port=8000:interface=127.0.0.1
Mar 12 10:50:39 AM  2021-03-12 10:50:39,400 INFO     Listening on TCP address 127.0.0.1:8000

But the deployment cannot be finalized (it runs indefinetely).

Any idea what I am doing wrong? Is there a problem with the IPs ? Django-channels guidelines indicate we can also specify the port and IP that Daphne binds to. e.g. :

daphne -b 0.0.0.0 -p 8001 myproject.asgi:application

Thanks a lot

Hey @jpuaux, I think you may have answered your own question! Render services should bind to 0.0.0.0 (all available network interfaces) rather than 127.0.0.1 (localhost). Let us know if you continue to see issues after making that change.

It is working with the following command :

daphne -b 0.0.0.0 pcaexpress.asgi:application

Thanks a lot for your answer.

1 Like

is there any way to use these both commands

gunicorn project.wsgi
daphne -b 0.0.0.0 project.asgi:application

because I am using this command: daphne -b 0.0.0.0 project.asgi:application, I am getting an error in google login but when my
starting command was: gunicorn project.wsgi, google login works perfectly.

Hey there - this isn’t a Render issue.

You’re getting an Error 400 there from Google - the redirect URL you are requesting is different to what the oAuth client on Google is configured with so Google rejects the request.

John B

Hi im dealing with this issue too. I also need to run daphne and gunicorn because with daphne i can not use csrf. So, i have the same question, how can i run both gunicorn and daphne? Thank you!

try running this if you can access the terminal

pip install -U 'Twisted[tls,http2]'

if you can access the terminal, add Twisted[tls,http2] to the bottom of your requirements.txt

hey please i have same problem when my start command is daphne -b 0.0.0.0 root.asgi:application i get an endless deployment sort of loop that never stops deploying. if i change it to this daphne chat.asgi:application --port $PORT --bind 0.0.0.0 it deploys but i get This page isn’t workingepschat.onrender.com redirected you too many times.
Try deleting your cookies.
ERR_TOO_MANY_REDIRECTS

Same for me, It is endlessly deploying.

2024-01-01 22:52:49,281 INFO     Starting server at tcp:port=8000:interface=0.0.0.0
2024-01-01 22:52:49,282 INFO     HTTP/2 support enabled
2024-01-01 22:52:49,282 INFO     Configuring endpoint tcp:port=8000:interface=0.0.0.0
2024-01-01 22:52:49,282 INFO     Listening on TCP address 0.0.0.0:8000

Try replacing the port number you use with the default one Render uses when deploying an app. I think it’s 10000.
So instead of daphne --port 8000 --bind 0.0.0.0 myproject.asgi:application,
use daphne --port 10000 --bind 0.0.0.0 myproject.asgi:application.
This worked for me.

1 Like

this worked on render.com. kudos to @alimi-ajibade

daphne --port 10000 --bind 0.0.0.0 myproject.asgi:application

daphne -b 0.0.0.0 --port 10000 myproject.asgi:application

Hi guys, I’m currently trying to deploy django channels + celery worker + celery beat , all under one web service. Is this supported by render ? My daphne server starts and seems to work fine but not the celery worker and beat. I was able to achieve this before implementing channels/daphne. I would really appreciate if anyone could advise on this. The start script I am using is the following:

Start Daphne for both HTTP and WebSocket traffic

daphne -b 0.0.0.0 -p 10000 django_core.asgi:application

Start Celery worker

celery -A django_core worker --loglevel=info -c 4 &

Start Celery beat scheduler

celery -A django_core beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler &

I have also tried using supervisor to manage the processes but i got a lot of error regarding logging. Thanks in advance !