Django Heroku 简介

Django Heroku Profile

我在 Heroku 上 运行 我的 django 应用程序遇到问题。以下是我的文件结构:

---django_blog
   ---media_cdn
   ---static_cdn
   ---Procfile
   ---requirements.txt
   ---runtime.txt
   ---src
      ---blog
         ---...
         ---settings.py
      ---manage.py
      ---...

所以 'src' 实际上是我的项目根目录,'blog' 是我的应用程序。我尝试将 procfile 设为

web: blog.wsgi --log-file -

web: src.blog.wsgi --log-file -

但其中 none 有效。当我检查 heroku 日志文件时,我发现了这个错误:

ImportError: No module named 'blog'

来自 Heroku 文档:

First, and most importantly, Heroku web applications require a Procfile.

This file (named Procfile) is used to explicitly declare your application’s process types and entry points. It is located in the root of your repository.

你需要更具体地说明你如何声明你的进程类型,如果你为此使用 gunicorn 你将声明 --chdir 因为你想 运行 它来自不同的文件夹:

web: gunicorn --chdir src myproject.wsgi --log-file -

另一方面,我没有使用 gunicorn,而是这样声明的:

web: python myproject/manage.py runserver 0.0.0.0:$PORT --noreload

仅供参考 - 在生产中切换到 gunicorn