[Django]-Websocket connection not working in Django Channels ('WebSocket connection to 'ws://localhost:8000/ws/board/7/' failed:')

6👍

Maybe you installed channels version 4 which is the latest, default one, and this does not start the ASGI server in development mode. please verify this and install channels version == 3.0.5 . do verify ASGI server starts when you run the runserver command.

( Version 4 supports ASGI server via daphne, I guess so, not tried.)

If not let me know will discuss more.

enter image description here

4👍

  • For channels==4.0.0 there was a change mentioned here which requires that you also put daphne in INSTALLED_APPS, before django.contrib.staticfiles. Run also pip install -U 'channels[daphne]' channels-redis to be sure you have compatible daphne and channels-redis versions.

  • Alternatively, seems that running daphne <your main app>.asgi:application from within your root of your project (where manage.py is) instead of the python manage.py runserver works.

  • Additionally, as mentioned before, downgrading to channels==3.0.5 is another way to make it work without adding daphne to your INSTALLED_APPS.

👤mpliax

0👍

you are missing this in settings.py file

ASGI_APPLICATION = 'appname.asgi.application'

Leave a comment