我正在尝试在 Django 中创建套接字。我按照这个安装了 asgi_redis link .
当我运行命令 python manage.py runserver 时,出现以下错误。
>python manage.py runserver
CommandError: You have not set ASGI_APPLICATION, which is needed to run the server.
由于我还没有启动redis,上面的错误可能是因为这个。我有点困惑,我需要单独安装Redis还是只需要启动redis,因为我已经安装了asgi_redis?
redis 的 project/settings.py 文件条目。
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'asgi_redis.RedisChannelLayer',
'CONFIG': {
'hosts': [('localhost', 6379)],
},
'ROUTING': 'example_channels.routing.channel_routing',
}
}
最佳答案
您应该为 WebSocket 服务器编写路由配置。创建文件 mysite/routing.py
在 settings.py
的同一文件夹中文件并包含以下代码:
# mysite/routing.py
from channels.routing import ProtocolTypeRouter
application = ProtocolTypeRouter({
# (your routes here)
})
您也可能忘记将 Channels 指向根路由配置。编辑 mysite/settings.py 文件并将以下内容添加到它的底部:ASGI_APPLICATION = 'mysite.routing.application'
关于python - django:redis:CommandError: 你没有设置ASGI_APPLICATION,这是运行服务器所需要的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58841118/