英文:
Firefox can’t establish a connection to the server in django channels echo server
问题
我使用Django Channels编写了一个回声服务器,我将给你链接
当我尝试连接到回声服务器时,控制台显示以下错误
`Firefox 无法建立与服务器ws://127.0.0.1:8000/ws/的连接
套接字意外关闭
`
以及在终端中-->未找到:/ws/
在Chrome浏览器中我也遇到了相同的错误
我多次卸载并重新安装了Channels甚至Django项目
但是没有效果
问题出在哪里?
英文:
I wrote an echo server with Django Channels, which I will give you the link
When I try to connect to Echo Server, I get this error in the console
`Firefox can’t establish a connection to the server at ws://127.0.0.1:8000/ws/
Socket closed unexpectedly
`
and In terminal-->not found:/ws/
I get the same error in the Chrome browser
I uninstalled and reinstalled Channels and even the Django project several times
But it didn't work
where is the problem from?
答案1
得分: 0
我自己找到了解决方法。
在routing.py(echo app)中,在consumer类后面加了as_asgi()
,然后它就起作用了。
在echo/routing.py中:
path('ws/', consumers.EchoConsumer.as_asgi())
英文:
I found the solution myself.
I put an as_asgi()
in the routing.py (echo app) after the consumer class and it worked.
In echo/routing.py:
path('ws/',consumers.EchoConsumer.as_asgi())
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论