如何为Heroku上部署的Mezzanine应用程序设置`Procfile`

时间:2015-06-17 11:00:51

标签: django heroku mezzanine

我已经在Heroku上部署了Mezzanine应用程序。系统之前运行正常,但今天网页显示错误消息Internal Server Error。与heroku logs签话后发现命令web python manage.py run_gunicorn -b 0.0.0.0:$PORT -w 1已弃用,Heroku建议使用<projName>.wsgi:application

但Mezzanine目前有不同的项目布局来自Django(Mezzanine的settings.py位于项目根目录中),所以我在Procfile中尝试了以下内容:

web: gunicorn wsgi --log-file -

但是,这样的设置会导致错误消息:

ImportError: No module named 'app'
...
ImportError: Could not import settings 'app.settings' (Is it on sys.path? Is there an import error in the settings file?) No module named 'app'.

然后我尝试了:

web: gunicorn <projName>.wsgi --log-file -

错误信息(当然; - ):

ImportError: No module named '<projName>'

那么,如何设置Procfile以便gunicorn能够找到项目的settings.pywsgi.py

1 个答案:

答案 0 :(得分:0)

wsgi.py的内容:

from __future__ import unicode_literals

import os

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
settings_module = "%s.settings" % PROJECT_ROOT.split(os.sep)[-1]
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)

from django.core.wsgi import get_wsgi_application

if 'DYNO' in os.environ:     # For Heroku
    from dj_static import Cling  
    application = Cling(get_wsgi_application())
else:
    application = get_wsgi_application()