Django 通道无法导入名称请求从异常中止



使用daphne,这是我的设置:

文件:

web: daphne my_application.asgi:application --port $PORT --bind 0.0.0.0 -v2

设置

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'channels',
'django_summernote',
....
]
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
}
}
} 
ASGI_APPLICATION = "my_application.routing.application"

路由文件:

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.conf.urls import url
application = ProtocolTypeRouter({
'websocket': AuthMiddlewareStack(
URLRouter(
[
url(*),
....
]
)
),
})

阿斯吉。PY - 发生错误的位置

"""
ASGI entrypoint. Configures Django and then runs the application
defined in the ASGI_APPLICATION setting.
"""
import os
import django
# HERE IT THROWS THE IMPORT ERROR
from channels.routing import get_default_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_application.settings")
django.setup()
application = get_default_application()  

要求:

...
channels
channels_redis
...

因此,使用最新的2。(2?)我相信我刚刚验证的软件包具有所需的源代码。


导入错误

from channels.exceptions import RequestAborted, RequestTimeout
ImportError: cannot import name 'RequestAborted'

我显然有正确的软件包,并且可以根据源代码使用,因此 wtf 在这里进行.....?

正如@chander所提到的:问题是你安装了django频道,而你已经有频道了。 要解决问题,请运行:

点子卸载 django 频道

点子卸载通道

点安装通道

我猜你做了一个:

点子安装姜戈频道

而你应该做的

点安装通道

安装最新版本的频道。

我遇到了类似的问题 - 最后我吹走了我的 venv 和 pyenv 并重新安装 - 这解决了这个问题。 当我已经安装了频道时,我不小心安装了 django 频道,问题就开始了。

最新更新