网站加载正常,但频道不工作。在控制台中,我得到:WebSocket 连接到 'ws://fortests.ovh/8' 失败:WebSocket 握手期间出错:意外响应代码:404
服务器:Ubuntu 16.04 on Digital Ocean nginx 版本:nginx/1.10.0 (Ubuntu) Redis 服务器 v=3.2.8
我的设置.py:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'asgi_redis.RedisChannelLayer',
'CONFIG': {
'hosts': [('localhost', 6379)],
},
'ROUTING': 'slist.routing.channel_routing',
}
}
Run Code Online (Sandbox Code Playgroud)
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "slist.settings")
application = get_wsgi_application()
Run Code Online (Sandbox Code Playgroud)
消费者.py
import json
from channels import Group
from channels.auth import channel_session_user_from_http, channel_session_user
from .models import Item
# Connected to websocket.connect
@channel_session_user_from_http
def ws_add(message):
# Accept the connection
message.reply_channel.send({"accept": True})
# Add to the users …Run Code Online (Sandbox Code Playgroud)