ASGI_APPLICATION not working with Django Channels
Question:
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 = ''
.
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
Use version of python that support by channels, you will found it at pypi channels page
I had the same problem, and found that there was a new release of Channels. Since the project’s Pipfile did not specify a version, it was automatically upgraded.
Maybe you had the same issue, your question was asked 2 days after Channels v4.0 release.
Downgrading to v3.0.5 again solved the problem until I can properly upgrade.
Had the same with django=4.1.4, channels=4.0.0
My solution:
- install channels with daphne (i did not remove or did anything to previously installed channels; operating in the same venv)
python -m pip install -U channels["daphne"]
- put daphne in INSTALLED APPS, do not put channels there:
INSTALLED_APPS = ( "daphne", "django.contrib.auth",...
- in settings.py add ASGI_APPLICATION:
ASGI_APPLICATION = "myproject.asgi.application"
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.
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 = ''
.
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
Use version of python that support by channels, you will found it at pypi channels page
I had the same problem, and found that there was a new release of Channels. Since the project’s Pipfile did not specify a version, it was automatically upgraded.
Maybe you had the same issue, your question was asked 2 days after Channels v4.0 release.
Downgrading to v3.0.5 again solved the problem until I can properly upgrade.
Had the same with django=4.1.4, channels=4.0.0
My solution:
- install channels with daphne (i did not remove or did anything to previously installed channels; operating in the same venv)
python -m pip install -U channels["daphne"]
- put daphne in INSTALLED APPS, do not put channels there:
INSTALLED_APPS = ( "daphne", "django.contrib.auth",...
- in settings.py add ASGI_APPLICATION:
ASGI_APPLICATION = "myproject.asgi.application"
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.