意外响应代码:尝试连接Django通道时javascript控制台中出现404错误
我正在尝试按以下路径路由websocket意外响应代码:尝试连接Django通道时javascript控制台中出现404错误,javascript,python,django,Javascript,Python,Django,我正在尝试按以下路径路由websocket matrix.routing -> ws_consumer.routing -> chat.routing. 应用程序结构 matrix是我的应用程序名,另外两个(ws\u consumer,chat)是应用程序。 这些文件中的配置如下所示 matrix.routing.py ws_consumer.routing.py chat.routing.py 在这些配置下,服务器正在启动,没有任何问题。但在控制台中,我得到以下错误 javasc
matrix.routing -> ws_consumer.routing -> chat.routing.
应用程序结构
matrix
是我的应用程序名,另外两个(ws\u consumer
,chat
)是应用程序。
这些文件中的配置如下所示
matrix.routing.py
ws_consumer.routing.py
chat.routing.py
在这些配置下,服务器正在启动,没有任何问题。但在控制台中,我得到以下错误
javascript控制台
python控制台
我还尝试在matrix.routing.py
中直接路由到消费者,这会导致相同的错误
matrix.routing.py
我在这里做错了什么?我发现问题不包括settings.py的已安装应用程序的“频道”
/matrix ->
/matrix
/wsconsumer
/chat
ws_consumer_regex = r'^/ws_consumer'
channel_routing = [
include('ws_consumer.routing', path=ws_consumer_regex),
]
chat_regex = r'^/chat'
notification_regex = r'^/notification'
channel_routing = [
include('chat.routing', path=chat_regex),
include('notification.routing', path=notification_regex),
]
group_chat_name_regex = r'^/(?P<group_name>[a-zA-Z0-9_]+)/$'
group_chat_routing = [
route('websocket.connect', consumers.group_chat_connect, path=group_chat_name_regex),
route('websocket.receive', consumers.group_chat_receive, path=group_chat_name_regex),
route('websocket.disconnect', consumers.group_chat_disconnect, path=group_chat_name_regex),
]
group_chat_global_regex = r'^/group'
channel_routing = [
include(group_chat_routing, path=group_chat_global_regex),
]
var socket = new WebSocket('ws://' + window.location.host + '/ws_consumer/chat/group/test/');
socket.onopen = function open() {...};
socket.onmessage = function (event) {...};
if (socket.readyState == WebSocket.OPEN) {
socket.onopen();
}
VM2306:35 WebSocket connection to 'ws://localhost:8000/ws_consumer/chat/group/test/' failed: Error during WebSocket handshake: Unexpected response code: 404
Not Found: /ws_consumer/chat/group/test/
[19/Mar/2017 23:42:39] "GET /ws_consumer/chat/group/test/ HTTP/1.1" 404 2202
from chat.consumers import group_chat_connect #consumer method
channel_routing = [
route('websocket.connect', group_chat_connect)
]