我正在尝试在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 = []
请帮我调试一下,找出错误。我正在尝试构建的游戏是多人文字游戏,两个用户可以互相竞争,并通过在有限的时间内回答一个问题来获得尽可能多的积分!
2条答案
按热度按时间5f0d552i1#
将我的www.example.com更改settings.py为:
解决了这个问题。我不知道最初为什么它不工作!
btqmn9zl2#
如果settings.py上的所有内容都配置正确,但仍然遇到无法导入ASGI_APPLICATION模块“project. routing”错误,这意味着www.example.com文件上发生了一些错误routing.py。
在这种情况下,再次仔细检查routing.py代码,查看是否有任何错误或打字错误。
这是我的案子。