django:redis:CommandError:您尚未设置ASGI_APPLICATION,这是运行服务器所需的 [英] django:redis:CommandError: You have not set ASGI_APPLICATION, which is needed to run the server
问题描述
我正在尝试在Django中创建套接字.我按照链接安装了asgi_redis.当我运行命令python manage.py runserver时,出现以下错误.
I am trying to create socket in django. I installed asgi_redis as per this link. When I ran the command python manage.py runserver, I am getting below error.
>python manage.py runserver
CommandError: You have not set ASGI_APPLICATION, which is needed to run the server.
由于我还没有启动Redis,因此可能出现上述错误.我有点困惑,我是否需要单独安装Redis还是只需要启动Redis,因为我已经安装了asgi_redis?
As I havent started the redis, above error might be because of this. I am bit confused , do I need to install Redis separately or just need to start the redis as I have already installed the asgi_redis?
redis的project/settings.py文件条目.
project/settings.py file entry for redis.
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'asgi_redis.RedisChannelLayer',
'CONFIG': {
'hosts': [('localhost', 6379)],
},
'ROUTING': 'example_channels.routing.channel_routing',
}
}
推荐答案
您应该为WebSocket服务器编写路由配置.在 settings.py
文件的同一文件夹中创建文件 mysite/routing.py
,并包含以下代码:
You should write routing configuration for your WebSocket server. Create a file mysite/routing.py
in the same folder of the settings.py
file and include the following code:
# mysite/routing.py
from channels.routing import ProtocolTypeRouter
application = ProtocolTypeRouter({
# (your routes here)
})
您可能还忘记了将Channels指向根路由配置.编辑mysite/settings.py文件,并将以下内容添加到它的底部:
You also might forgot to point Channels at the root routing configuration. Edit the mysite/settings.py file and add the following to the bottom of it:
ASGI_APPLICATION = 'mysite.routing.application'
这篇关于django:redis:CommandError:您尚未设置ASGI_APPLICATION,这是运行服务器所需的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!