一尘不染

Django频道错误-无法导入BACKEND'asgi_redis.RedisChannelLayer'

redis

我已经安装了Django-Channels,但是在运行daphne-server时出现以下错误:

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

我的settings.py是:

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",
},
}

需要帮助解决此错误。


阅读 516

收藏
2020-06-20

共1个答案

一尘不染

只需安装“ asgi_redis”。我以为在安装Django-Channels时会默认安装它,但事实并非如此。默认情况下会安装“ asgiref”,而不是“
asgi_redis”。因此,要解决此问题,只需运行即可:

> sudo pip install asgi_redis
2020-06-20