Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASGI_APPLICATION not working with Django Channels

I followed the tutorial in the channels documentation but when I start the server python3 manage.py runserver it gives me this :

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 17, 2022 - 00:13:21
Django version 4.1.2, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

when I expected for it to give me this :

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 17, 2022 - 00:13:21
Django version 4.1.2, using settings 'config.settings'
Starting ASGI/Channels version 3.0.5 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

settings.py

INSTALLED_APPS = [
    'channels',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ...
]

ASGI_APPLICATION = 'config.asgi.application'

asgi.py

import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application = ProtocolTypeRouter({
    'http': get_asgi_application(),
})

It doesn't give any errors even when I change the ASGI_APPLICATION = 'config.asgi.application to ASGI_APPLICATION = ''.

like image 206
TheButterMineCutter Avatar asked Nov 25 '25 05:11

TheButterMineCutter


2 Answers

This could be due to the fact that the Django and channels versions you have used are not compatible Try : channels==3.0.4 and django==4.0.0

like image 115
Patrick Iradukunda Avatar answered Nov 26 '25 19:11

Patrick Iradukunda


At the first:

pip install daphne
pip install channels

And then update setting.py:

INSTALLED_APPS = [
    'daphne',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

Just this.

like image 21
reza_khalafi Avatar answered Nov 26 '25 17:11

reza_khalafi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!