Django channels 'No application configured for scope type 'websocket''

為{幸葍}努か 提交于 2019-12-04 05:17:26

问题


I am trying to implement a chat with Django and channels according to this tutorial (http://channels.readthedocs.io/en/latest/tutorial/part_2.html). I add channels and a chat app to installed apps. I make the following routings for a project:

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

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

Basically, I did exactly the steps from the tutorial. But after runserver I am still getting ValueError: No application configured for scope type 'websocket', after going to a specific chat room. Can please someone help me?


回答1:


You appear to be missing the websocket key. The tutorial says to add following imports and add the websocket key in 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
        )
    ),
})


来源:https://stackoverflow.com/questions/49283575/django-channels-no-application-configured-for-scope-type-websocket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!