5

我是 Django 频道的新手并遵循教程(https://channels.readthedocs.io/en/latest/tutorial/part_2.html

由于 Redis 不支持 Windows 7,我从 ( https://github.com/dmajkic/redis/downloads )下载了 Redis 2.4 版

当我尝试从 Django shell 访问 Redis 时,我收到了主题中提到的错误。

$ python3 manage.py shell
>>> import channels.layers
>>> channel_layer = channels.layers.get_channel_layer()
>>> from asgiref.sync import async_to_sync
>>> async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})
>>> async_to_sync(channel_layer.receive)('test_channel')      # ERROR OCCURED AFTER THIS STEP

正如您在下面看到的,Redis 文件夹,它在端口 6379 处启动开发服务器。 在此处输入图像描述

4

1 回答 1

10

我在同一个教程之后遇到了同样的问题,包括一个类似的旧项目突然停止工作......以下更改解决了我的问题:

前:

CHANNEL_LAYERS = {
    'default': {
       'BACKEND': 'channels_redis.core.RedisChannelLayer',
       'CONFIG': {
            'hosts': [('127.0.0.1', 6379)]
        },
    },
}

解决方案:

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer"
   }
}

来源:https ://channels.readthedocs.io/en/latest/topics/channel_layers.html#in-memory-channel-layer

于 2020-08-28T23:22:05.933 回答