python - django:redis:CommandError: 你没有设置ASGI_APPLICATION,这是运行服务器所需要的

标签 python django redis

我正在尝试在 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.pysettings.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/

相关文章:

jquery - 在 Django 中实现 Ajax 搜索

python - Django View : working with a file result in indentation error

python - 如何对 Django 中的所有模型对象进行向后关系查找?

.net - 如何使用 ConnectionMultiplexer 在 Redis 集群中处理故障转移?

Wordpress 管理栏不断向访问者显示

redis - 多个订阅一个主题

python - 我怎样才能将每个对象与每个对象进行比较?

python - docopt 位置参数不起作用

python - 正则表达式匹配 Django 项目中 URL 模式中使用的字母和数字的组合?

python 正则表达式匹配大小写选项