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

2

11

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',
    }
}
Electrotechnology answered 13/11, 2019 at 16:7 Comment(1)
The tutorial you linked to is for channels 1.x. You should look for a guide written for channels 2.x, because a lot changed.Indemnify
N
17

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)
})

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'
Nice answered 12/1, 2020 at 10:24 Comment(0)
B
0

You have to Add this code in your settings.py file change the name of the "ChatApp" to the actual name of your application and add this code just below to the INSTALLED_APPS code in the settings.py file

ASGI_APPLICATION = 'ChatApp.asgi.application'

and now click new terminal then Go cd ./ChatApp then py manage.py runserver and you see your server is running

Bombshell answered 29/8 at 1:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.