我正在关注Channels文档的入门教程,但是当我启动runserver并尝试加载任何页面时,它会给我这个错误:
16:17:46 [django.request] ERROR Internal Server Error: /
Traceback (most recent call last):
File "C:\web\wr-kpi-dashboard\.venv\lib\site-packages\django\core\handlers\base.py", line 235, in get_response
response = middleware_method(request, response)
File "C:\web\wr-kpi-dashboard\.venv\lib\site-packages\wr_security\middleware\log_access.py", line 39, in process_response
'protocol': request.META['SERVER_PROTOCOL'],
KeyError: 'SERVER_PROTOCOL'
[2017/09/06 16:17:47] HTTP GET / 500 [0.63, 127.0.0.1:60297]
settings.py
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgiref.inmemory.ChannelLayer",
"ROUTING": "dashboard.channels.routing.channel_routing",
},
}
routing.py
from channels.routing import route
from consumers import ws_message
channel_routing = [
route("websocket.receive", ws_message),
]
consumers.py
def ws_message(message):
# ASGI WebSocket packet-received and send-packet message types
# both have a "text" key for their textual data.
message.reply_channel.send({
"text": message.content['text'],
})