我正在尝试在 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",
},
}
路由.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 = []
请帮我调试它并找出错误。我正在尝试构建的游戏是多人文字游戏,其中两个用户可以相互竞争并通过在有限的时间内回答一个问题来获得尽可能多的分数!