我正在尝试根据本教程(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'
之后进入特定的聊天室。可以请别人帮助我吗?
答案 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
)
),
})