django:redis:CommandError: You have not set ASGI_APPLICATION, which is needed to run the server

末鹿安然 提交于 2021-02-19 02:20:10

问题


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.

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?

project/settings.py file entry for redis.

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'asgi_redis.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('localhost', 6379)],
        },
        'ROUTING': 'example_channels.routing.channel_routing',
    }
}

回答1:


You should write routing configuration for your WebSocket server. Create a file mysite/routing.py and include the following code:

# mysite/routing.py
from channels.routing import ProtocolTypeRouter

application = ProtocolTypeRouter({
    # (your routes here)
})

You probably 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'

`



来源:https://stackoverflow.com/questions/58841118/djangorediscommanderror-you-have-not-set-asgi-application-which-is-needed-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!