在Django通道上找不到路径

2024-05-28 20:21:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Django channels应用程序上创建了一个简单的使用者,但当我尝试从前端连接到websocket时,我不断收到以下错误:

ws_protocol: ERROR - [Failure instance: Traceback: <class 'ValueError'>: No route found for path 'messages/127.0.0.1:8000/messages/'.

以下是我的路线: myapp>;路由.py

from .consumers import EchoConsumer

websocket_urlpatterns = [
    path("messages/", EchoConsumer),
]

mysite>;路由.py

# mysite/routing.py
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import myapp.routing

application = ProtocolTypeRouter({
    # (http->django views is added by default)
    'websocket': AuthMiddlewareStack(
        URLRouter(
            myapp.routing.websocket_urlpatterns
        )
    ),
})

下面是我如何尝试从前端连接到websocket:

var wsStart = 'ws://' + window.location.host + window.location.pathname

谁能帮我找出我做错了什么


Tags: pathfrompyimportgt路由wsrouting

热门问题