简体   繁体   English

在 heroku 上部署 django 通道

[英]Deploying django channels on heroku

I have created a standard django application with startproject, startapp, etc. and I want to deploy it on heroku.我用 startproject、startapp 等创建了一个标准的 django 应用程序,我想将它部署在 heroku 上。 When I was using gunicorn I solved the directory issue like so:当我使用 gunicorn 时,我像这样解决了目录问题:

web: gunicorn --pythonpath enigma enigma.wsgi

with the --pythonpath option.使用 --pythonpath 选项。 But now I am using django channels and so it is daphne.但现在我使用的是 django 通道,所以它是 daphne。 Is there an equivalent?有没有等价物? I have tried everything but for the life of me I can't get the project to start.我已经尝试了一切,但对于我的一生,我无法启动该项目。 I always get issues with the settings file, apps not loaded or another assortment of cwd-related issues.我总是遇到设置文件、未加载应用程序或其他各种 cwd 相关问题的问题。

As given in the Heroku Django channels tutorial, I have tried:正如 Heroku Django 频道教程中给出的,我尝试过:

daphne enigma.asgi:channel_layer --port 8888

This led to a variety of module not found errors with asgi and settings.这导致了各种模块未找到 asgi 和设置的错误。

I also tried我也试过

daphne enigma.enigma.asgi:channel_layer --port 8888

This led to module not found enigma.settings errors.这导致 module not found enigma.settings 错误。

I also tried我也试过

cd enigma && daphne enigma.asgi:channel_layer --port 8888

Which led to Django apps not ready errors.这导致 Django 应用程序未准备好错误。

I also tried moving the Procfile and pipfiles into the project directory and deploying that subdirectory but once again I got apps not ready errors.我还尝试将 Procfile 和 pipfiles 移动到项目目录并部署该子目录,但我再次遇到应用程序未就绪错误。

I have now started temporarily using我现在已经开始临时使用

cd enigma && python manage.py runserver 0.0.0.0:$PORT

But I know that you're not supposed to do this in production.但我知道你不应该在生产中这样做。

Try this:尝试这个:

Procfile档案

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

settings.py设置.py

if DEBUG:
    CHANNEL_LAYERS = {
        "default": {
            "BACKEND": "channels_redis.core.RedisChannelLayer",
            "CONFIG": { 
                "hosts": [("localhost", 6379)],
            },
        },
    }
else:
    CHANNEL_LAYERS = {
        "default": {
            "BACKEND": "channels_redis.core.RedisChannelLayer",
            "CONFIG": { 
                "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
            },
        },
    }

asgi.py asgi.py

import os, django
from channels.routing import get_default_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'enigma.settings')
django.setup()
application = get_default_application()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM