0
次のパスでwebsocketをルーティングしようとしています。予期しない応答コード:Djangoチャンネルに接続しようとしているときにjavascriptコンソールで404エラーが発生しました
matrix.routing -> ws_consumer.routing -> chat.routing.
アプリケーション構造
/matrix ->
/matrix
/wsconsumer
/chat
matrix
は、私のアプリケーション名で、他の2つ(ws_consumer
、chat
は)アプリケーションです。
matrix.routing.py
ws_consumer_regex = r'^/ws_consumer'
channel_routing = [
include('ws_consumer.routing', path=ws_consumer_regex),
]
ws_consumer.routing.py
chat_regex = r'^/chat'
notification_regex = r'^/notification'
channel_routing = [
include('chat.routing', path=chat_regex),
include('notification.routing', path=notification_regex),
]
chat.routing.py
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),
]
クライアントを次のようにこれらのファイル内 構成です。 html
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();
}
これらの設定では、サーバーは問題なく起動しています。しかし、コンソールで私はエラーの下になっています。
JavaScriptコンソール
のpythonコンソール
Not Found: /ws_consumer/chat/group/test/
[19/Mar/2017 23:42:39] "GET /ws_consumer/chat/group/test/ HTTP/1.1" 404 2202
私も同じエラーに私を取るmatrix.routing.py
で消費者に直接ルーティングを試してみました。
matrix.routing.py
from chat.consumers import group_chat_connect #consumer method
channel_routing = [
route('websocket.connect', group_chat_connect)
]
は、私がここで間違って何をしているのですか?