我在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
谁能帮我找出我做错了什么
您使用的是路径而不是url,请在routing.py中尝试以下操作:
相关问题 更多 >
编程相关推荐