首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Daphne服务Django和Channels

用Daphne服务Django和Channels
EN

Stack Overflow用户
提问于 2017-07-20 00:06:50
回答 1查看 1K关注 0票数 0

我在Google Compute Engine上有一个Django项目。这是我的Django项目的结构。

代码语言:javascript
复制
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

按照教程中的说明,我制作了asgi.pyб

代码语言:javascript
复制
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作为后端。设置文件如下所示:

代码语言:javascript
复制
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'asgi_redis.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('localhost', 6379)],
        },
        'ROUTING': 'example_channels.routing.channel_routing',
    }
}

然后,我尝试启动服务器。我运行python manage.py runworker &并获取:

代码语言:javascript
复制
~/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

然后运行Daphne:

代码语言:javascript
复制
~/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错误。

EN

回答 1

Stack Overflow用户

发布于 2017-08-16 01:22:54

尝试在端口8000上使用daphne,并在settings.py中检查ALLOWED_HOSTS="*“

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45195738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档