我在 heroku 上使用 Channels 2 创建了一个 django 应用程序,但它在启动时崩溃并显示 503 错误代码。
2020-04-07T10:05:35.226253+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.mysite.com request_id=317bfbe6-9055-4957-9fbb-8190616c3964 fwd="" dyno= connect= service= status=503 bytes= protocol=https
简介:
release: python manage.py migrate
web : daphne myproject.asgi:application --port $PORT --bind 0.0.0.0 -v2
worker: python manage.py runworker channels -v2
设置.py
ASGI_APPLICATION = 'myproject.routing.application'
# Channels
CHANNEL_LAYERS = {
"default": {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
"CONFIG": {
"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
},
},
}
asgi.py
import os
import django
from channels.routing import get_default_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
django.setup()
application = get_default_application()
最佳答案
您是否在 heroku 中创建了 process web 的实例?
您可以在命令行中执行此操作:heroku ps:scale worker=1
在 Procfile 中将 worker 设置为:
worker: python manage.py runworker channels --settings=<project-name>.settings -v2
关于Django Channel 2 和 Daphne on Heroku 在开始时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61077627/