Search code examples
pythondjangowsgidjango-channelsasgi

django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'routing'


I am trying to build a multiplayer game in Django, for which I needed to work on Django channels. but here's the issue while running it.

Performing system checks...

System check identified no issues (0 silenced).
September 27, 2019 - 05:38:35
Django version 2.2.5, using settings 'multiproject.settings'
Starting ASGI/Channels version 2.1.5 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/augli/.local/lib/python3.6/site-packages/channels/routing.py", line 33, in get_default_application
    module = importlib.import_module(path)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'routing'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/augli/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/home/augli/.local/lib/python3.6/site-packages/channels/management/commands/runserver.py", line 101, in inner_run
    application=self.get_application(options),
  File "/home/augli/.local/lib/python3.6/site-packages/channels/management/commands/runserver.py", line 126, in get_application
    return StaticFilesWrapper(get_default_application())
  File "/home/augli/.local/lib/python3.6/site-packages/channels/routing.py", line 35, in get_default_application
    raise ImproperlyConfigured("Cannot import ASGI_APPLICATION module %r" % path)
django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'routing'


Here's my settings.py file:

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

WSGI_APPLICATION = 'multiproject.wsgi.application'
ASGI_APPLICATION = "routing.application"

CHANNEL_LAYERS = {
 "default": {
 "BACKEND": "asgiref.inmemory.ChannelLayer",
 "ROUTING": "multiproject.routing.channel_routing",
 },
}

Routing.py:

from channels.routing import route, route_class
from channels.staticfiles import StaticFilesConsumer

# routes defined for channel calls
# this is similar to the Django urls, but specifically for Channels
channel_routing = []

Please help me debug it and figure out the errors. The game i am trying to build is multiplayer word game where two users can compete against each other and score as many points by answering to a question in limited amount of time!


Solution

  • Changing my settings.py to:

    ASGI_APPLICATION = "multiproject.routing.application" 
    

    Solved this issue. I don't know initially why it didn't work!