使用通道2的runserver时无法导入ASGI

使用通道2的runserver时无法导入ASGI

本文介绍了使用通道2的runserver时无法导入ASGI_APPLICATION模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照频道教程进行操作,但是在运行这些错误抛出时

I have followed the channels tutorial but while running these error throw

软件包的版本为
channels == 2.1.2
Django == 2.0.4

我错过了什么?
in settings.py

what I missed ?in settings.py

INSTALLED_APPS = [
   "channels"
    ....
]

ROOT_URLCONF = 'myapp.urls'
ASGI_APPLICATION = "myapp.routing.application"

添加的文件mayapp / routing.py

added file mayapp/routing.py

from channels.routing import ProtocolTypeRouter

application = ProtocolTypeRouter({
    # Empty for now (http->django views is added by default)
})

这是错误日志

System check identified no issues (0 silenced).
August 01, 2018 - 13:11:42
Django version 2.0.4, using settings 'myapp.local_settings'
Starting ASGI/Channels version 2.1.2 development server at http://127.0.0.1:8080/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f71ecfb6400>
Traceback (most recent call last):
  File "/home/vkchlt0192/myapp/lib/python3.5/site-packages/channels/routing.py", line 33, in get_default_application
    module = importlib.import_module(path)
  File "/home/vkchlt0192/myapp/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'myapp.routing'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vkchlt0192/myapp/lib/python3.5/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/vkchlt0192/myapp/lib/python3.5/site-packages/channels/management/commands/runserver.py", line 80, in inner_run
    application=self.get_application(options),
  File "/home/vkchlt0192/myapp/lib/python3.5/site-packages/channels/management/commands/runserver.py", line 105, in get_application
    return StaticFilesWrapper(get_default_application())
  File "/home/vkchlt0192/myapp/lib/python3.5/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 'myapp.routing'


推荐答案

检查是否有潜在的错误(消费者中可能存在导入错误)。
另外,尝试将频道作为设置的第一项放在INSTALLED_APPS中。

Check for any potential errors (maybe import error) in consumers.py.Also, try to put channels as the first item in INSTALLED_APPS in settings.py.

如频道文档中所述:

这篇关于使用通道2的runserver时无法导入ASGI_APPLICATION模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:24