我正在尝试在Django中构建多人游戏,为此我需要在Django渠道上工作。但是这是运行时的问题。
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'
这是我的settings.py文件:
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 = []
请帮助我调试它并找出错误。我正在尝试开发的游戏是多人文字游戏,其中两个用户可以在有限的时间内回答问题,从而相互竞争并获得尽可能多的积分!
答案 0 :(得分:0)
将我的settings.py更改为:
ASGI_APPLICATION = "multiproject.routing.application"
解决了此问题。最初我不知道为什么它不起作用!