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