官方教程
https://channels.readthedocs.io/en/latest/tutorial/index.html
细节
库
pip install channels
pip install channels-redis
settings
# Channels
ASGI_APPLICATION = 'websocketTest.routing.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
ws url 匹配示例
websocket_urlpatterns = [
url(r'^websocket/test/(?P<user>[^/]+)/', consumers.Consumer),
]
过程见官网实例