2017-07-19 21 views
0

我在Google Compute Engine上有一个Django项目。这是我的Django项目的结构。为Daphne提供Django和频道

example_channels 
├── db.sqlite3 
├── example 
│ ├── admin.py 
│ ├── apps.py 
│ ├── consumers.py 
│ ├── __init__.py 
│ ├── migrations 
│ │ 
│ ├── models.py 
│ ├── templates 
│ │ └── example 
│ │  ├── _base.html 
│ │  └── user_list.html 
│ ├── tests.py 
│ ├── urls.py 
│ └── views.py 
├── example_channels 
│ ├── asgi.py 
│ ├── __init__.py 
│ ├── routing.py 
│ ├── settings.py 
│ ├── urls.py 
│ └── wsgi.py 
└── manage.py 

继tutorialsб我做了一个asgi.py

import os 
from channels.asgi import get_channel_layer 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings") 

channel_layer = get_channel_layer() 

我用asgi_redis作为后端。设置文件看起来是这样的:

CHANNEL_LAYERS = { 
    'default': { 
     'BACKEND': 'asgi_redis.RedisChannelLayer', 
     'CONFIG': { 
      'hosts': [('localhost', 6379)], 
     }, 
     'ROUTING': 'example_channels.routing.channel_routing', 
    } 
} 

我再尝试启动服务器。我跑python manage.py runworker &,并得到:

~/websockets_prototype/example_channels$ 2017-07-19 16:04:19,204 - INFO - runworker - Usi 
ng single-threaded worker. 
2017-07-19 16:04:19,204 - INFO - runworker - Running worker against channel layer default (asgi_redis.core.RedisCha 
nnelLayer) 
2017-07-19 16:04:19,205 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconne 
ct, websocket.receive 

然后运行达芙妮:

~/websockets_prototype/example_channels$ 2017-07-19 16:05:28,619 INFO  Starting server 
at tcp:port=80:interface=0.0.0.0, channel layer example_channels.asgi:channel_layer. 
2017-07-19 16:05:28,620 INFO  HTTP/2 support not enabled (install the http2 and tls Twisted extras) 
2017-07-19 16:05:28,620 INFO  Using busy-loop synchronous mode on channel layer 
2017-07-19 16:05:28,620 INFO  Listening on endpoint tcp:port=80:interface=0.0.0.0 

我再开始发送请求到服务器,但我得到This site can’t be reached错误。

+0

您的网站是否等待一段时间,让您的网站无法达到的错误或? –

+0

你有没有想过这个? –

回答

0

达芙妮尝试在8000端口和评论你的ALLOWED_HOSTS =“*”]在settings.py