Django渠道'没有为范围类型配置应用程序' websocket''

时间:2018-03-14 16:56:49

标签: python django django-channels

我正在尝试根据本教程(http://channels.readthedocs.io/en/latest/tutorial/part_2.html)实现与Django和频道的聊天。我为已安装的应用添加频道和聊天应用。我为一个项目做了以下路线:

# mysite/routing.py
from channels.routing import ProtocolTypeRouter

application = ProtocolTypeRouter({
    # (http->django views is added by default)
})

基本上,我完成了教程中的步骤。但在runserver之后,我仍然在ValueError: No application configured for scope type 'websocket'之后进入特定的聊天室。可以请别人帮助我吗?

1 个答案:

答案 0 :(得分:6)

您似乎缺少websocket密钥。 tutorial表示要添加以下导入,并在websocket中添加mysite/routing.py密钥。

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import chat.routing

application = ProtocolTypeRouter({
    # (http->django views is added by default)
    'websocket': AuthMiddlewareStack(
        URLRouter(
            chat.routing.websocket_urlpatterns
        )
    ),
})