Firefox 无法与 Django Channels 回声服务器建立连接。

huangapple go评论78阅读模式
英文:

Firefox can’t establish a connection to the server in django channels echo server

问题

我使用Django Channels编写了一个回声服务器,我将给你链接

channels_echo_server

当我尝试连接到回声服务器时,控制台显示以下错误

`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

channels_echo_server

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())

huangapple
  • 本文由 发表于 2023年6月18日 21:40:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定