Python Django通道在runserver中没有错误,但在localhost上没有页面
我试图在现有的Django项目中设置Django频道,以前从未使用过它们。如果有帮助的话,我会遵循指南。您可以在下面看到我运行服务器时得到的信息,但是转到Python Django通道在runserver中没有错误,但在localhost上没有页面,python,django,django-channels,Python,Django,Django Channels,我试图在现有的Django项目中设置Django频道,以前从未使用过它们。如果有帮助的话,我会遵循指南。您可以在下面看到我运行服务器时得到的信息,但是转到127.0.0.1:8000只会给我一条消息“损坏,无法加载页面”错误。因为我不熟悉频道的概念,所以我很有可能在设置中错过了一些东西 pi@raspberrypi:~/o2ta_swdev_pie/o2ta_web $ python manage.py runserver Performing system checks... System
127.0.0.1:8000
只会给我一条消息“损坏,无法加载页面”错误。因为我不熟悉频道的概念,所以我很有可能在设置中错过了一些东西
pi@raspberrypi:~/o2ta_swdev_pie/o2ta_web $ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
May 11, 2017 - 23:30:18
Django version 1.10.4, using settings 'o2ta_web.settings'
Starting Channels development server at http://127.0.0.1:8000/
Channel layer default (asgiref.inmemory.ChannelLayer)
Quit the server with CONTROL-C.
2017-05-11 23:30:18,744 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
2017-05-11 23:30:18,748 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
2017-05-11 23:30:18,750 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
2017-05-11 23:30:18,753 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
2017-05-11 23:30:18,796 - INFO - server - Using busy-loop synchronous mode on channel layer
我已根据此requirements.txt安装了依赖项:
# requirements.txt
asgi-redis==1.0.0
channels==0.17.3
daphne==0.15.0
Django==1.10.4
并根据链接指南添加了consumers.py、routing.py和changed settings.py
上述输出是否表明了我的问题可能在哪里?我不知道还有什么地方可以看,因为我没有像我通常期望的那样在我的网页上获得任何调试信息(yesdebug=true
)
编辑:请参阅下面的my consumers.py和routing.py文件
# consumers.py
def ws_echo(message):
message.reply_channel.send({
'text': message.content['text'],
})
# routing.py
from channels.routing import route
channel_routing = [
route('websocket.receive', 'main.consumers.ws_echo')
]
我在settings.py中做了以下更改:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'channels',
'main'
]
CHANNEL_LAYERS = {
'default': {
'BACKEND': "asgiref.inmemory.ChannelLayer",
"ROUTING": "o2ta_web.routing.channel_routing",
},
}
发布访问WebGeline时收到的错误1:
错误-http://127.0.0.1:8000/
第2行:页面'http://127.0.0.1:8000/'无法加载。
第3行:消息已损坏
将整个错误页作为pic文件提供,控制台中显示加载资源失败:消息损坏
。这就是你要看到的一切。你的路由和消费者看起来怎么样?