本文介绍了Django频道错误-无法导入BACKEND'asgi_redis.RedisChannelLayer'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经安装了Django-Channels,但是在运行daphne服务器时,出现以下错误:
File /usr/local/lib/python2.7/dist-packages/channels/asgi.py,make_backend
中的第36行,无法导入为%s指定的BACKEND%r%(self.configs [name] ['BACKEND'],名称)
channels.asgi.InvalidChannelLayerError:无法导入为默认
我的settings.py是:
CHANNEL_LAYERS = {
默认值:{
BACKEND: asgi_redis.RedisChannelLayer,
CONFIG:{
hosts:[os.environ.get('REDIS_URL','redis:/ / XXXX:6379')],
},
ROUTING: MyProject.routing.channel_routing,
},
}
需要帮助来解决此错误。
解决方案
只需安装 asgi_redis。我以为默认会在安装Django-Channels时默认安装它,但是没有。默认情况下会安装 asgiref,而不是 asgi_redis。因此,要解决此问题,只需运行即可:
> sudo pip install asgi_redis
I have installed Django-Channels but while running the daphne-server I am getting this error given below:
File "/usr/local/lib/python2.7/dist-packages/channels/asgi.py", line 36, in make_backend
"Cannot import BACKEND %r specified for %s" % (self.configs[name]['BACKEND'], name)
channels.asgi.InvalidChannelLayerError: Cannot import BACKEND 'asgi_redis.RedisChannelLayer' specified for default
My settings.py is:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ.get('REDIS_URL', 'redis://X.X.X.X:6379')],
},
"ROUTING": "MyProject.routing.channel_routing",
},
}
Need help in resolving this error.
解决方案
Just needed to install 'asgi_redis'. I was assuming that it would have gotten installed by default while installing Django-Channels, but it doesn't. 'asgiref' gets installed by default and not 'asgi_redis'. So to solve this issue, one can just run:
> sudo pip install asgi_redis
这篇关于Django频道错误-无法导入BACKEND'asgi_redis.RedisChannelLayer'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!