gpt4 book ai didi

python - 在 Heroku 上部署 asgi 和 wsgi

转载 作者:太空宇宙 更新时间:2023-11-04 00:36:44 24 4
gpt4 key购买 nike

我正在尝试使用 asgi 以及现有的 wsgi 实现在 Heroku 上部署 Django Channels。我可以使用以下设置将 asgi 和 wsgi 部署到 heroku 吗?

我的过程文件:

web: gunicorn chatbot.wsgi --preload --log-file -
daphne: daphne chat.asgi:channel_layer --port $PORT --bind 0.0.0.0 -v2
chatworker: python manage.py runworker --settings=chat.settings -v2

我的 asgi.py 文件:

import os
from channels.asgi import get_channel_layer

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

channel_layer = get_channel_layer()

我的 wsgi.py 文件:

import os

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

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

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

还有我在 settings.py 中的 channel 层:

CHANNEL_LAYERS = {
'default': {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')]
},
'ROUTING': 'chat.routing.channel_routing',
}
}

最佳答案

弄清楚了,以防这可能与其他人相关。只使用 asgi 是最好的解决方案。我的 procfile 结束为:

web: daphne chat.asgi:channel_layer --port $PORT --bind 0.0.0.0 -v2
chatworker: python manage.py runworker --settings=chat.settings -v2

作为提供静态文件的解决方案,我更新了我的 routing.py 文件以包含一个 StaticFileConsumer。

关于python - 在 Heroku 上部署 asgi 和 wsgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43741696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com