Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django通道上找不到路径_Python_Django_Django Channels - Fatal编程技术网

Python 在Django通道上找不到路径

Python 在Django通道上找不到路径,python,django,django-channels,Python,Django,Django Channels,我在Django channels应用程序上创建了一个简单的使用者,但当我尝试从前端连接到websocket时,我不断收到以下错误: ws_protocol: ERROR - [Failure instance: Traceback: <class 'ValueError'>: No route found for path 'messages/127.0.0.1:8000/messages/'. mysite>routing.py from .consumers import E

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

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

from .consumers import EchoConsumer

websocket_urlpatterns = [
    path("messages/", EchoConsumer),
]
# 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中尝试以下操作:

from .consumers import EchoConsumer
from django.conf.urls import url

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