WebSocket连接到' ws:url'失败:在建立连接之前关闭WebSocket

时间:2018-02-20 12:04:33

标签: python django websocket django-channels

我是 Django频道的新手,当我浏览一些教程时,我遇到了这个项目Channels Examples。当我在我的系统中运行项目时,我收到以下错误。

127.0.0.1:56653 - - [20/Feb/2018:17:18:37] "GET /new/" 302 -
127.0.0.1:56653 - - [20/Feb/2018:17:18:38] "GET /royal-dawn-8676/" 200 1865
127.0.0.1:56653 - - [20/Feb/2018:17:18:38] "GET /static/chat.js" 304 -
127.0.0.1:56669 - - [20/Feb/2018:17:18:38] "WSCONNECTING /chat/royal-dawn-8676/" - -
127.0.0.1:56669 - - [20/Feb/2018:17:18:40] "WSDISCONNECT /chat/royal-dawn-8676/" - -
127.0.0.1:56677 - - [20/Feb/2018:17:18:41] "WSCONNECTING /chat/royal-dawn-8676/" - -
127.0.0.1:56677 - - [20/Feb/2018:17:18:43] "WSDISCONNECT /chat/royal-dawn-8676/" - -
127.0.0.1:56680 - - [20/Feb/2018:17:18:45] "WSCONNECTING /chat/royal-dawn-8676/" - -
127.0.0.1:56680 - - [20/Feb/2018:17:18:47] "WSDISCONNECT /chat/royal-dawn-8676/" - -

注意:我的Django版本-1.11.8,           频道版本1.1.6

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。添加这行代码。在ws_connect函数

上的chat / consumers.py上

def ws_connect(message): message.reply_channel.send({"accept": True}) ...