我已经安装了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", }, }
需要帮助解决此错误。
只需安装“ asgi_redis”。我以为在安装Django-Channels时会默认安装它,但事实并非如此。默认情况下会安装“ asgiref”,而不是“ asgi_redis”。因此,要解决此问题,只需运行即可:
> sudo pip install asgi_redis