【发布时间】:2019-12-23 17:50:26
【问题描述】:
使用 daphne 这是我的设置:
PROCFILE:
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(*),
....
]
)
),
})
ASGI.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 正在这里进行.....?
【问题讨论】:
标签: python django django-views django-channels channels