找不到" / lobby /" django-channels路由错误

时间:2018-04-04 01:47:04

标签: javascript django django-channels

routing.py

from channels import include, route
from chat import consumers
from . import game_consumers

channel_routing = [
    #game routing
    route('websocket.connect', game_consumers.ws_connect_lobby, path=r"^/lobby/$"),
    route('websocket.receive', game_consumers.ws_receive_lobby, path=r"^/lobby/$"),
    route('websocket.disconnect', game_consumers.ws_disconnect_lobby, path=r"^/lobby/$"),

app.js

Websocket = {
    lobby_socket: null,
    setup_ws_lobby : function(){
        Websocket.lobby_socket = new ReconnectingWebSocket(Websocket.ws_scheme + '://' + window.location.host + '/lobby/');
        Websocket.lobby_socket.onmessage = function(message) {
            //nothing yet
        };
    },
}
Websocket.setup_ws_lobby();

网址为127.0.0.1:8000/gameWebsocket.setup_ws_lobby()在页面加载时执行。我不知道自己做错了什么。我在加载页面时在Not Found: /lobby/控制台中收到错误python manage.py runserver。我的路线设置清楚,我的js设置似乎路由到那些路线。有人可以帮忙吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

代码有效;这是一个版本问题。升级到1.1.8并且有效