10

我的问题:

当使用gunicorn作为我的 WSGI HTTP 服务器时,工头无法找到 Django (wsgi?) 应用程序。

应用结构:

在我的 Django 应用程序中,我的结构如下:

<git_repository_root>/
  <django_project_root>/
    <configuration_root>/

<git_repository_root>包含项目管理和部署相关的东西(、requirements.txtProcfilefabfile.py

包含我的<django_project_root>Django 应用程序和应用程序逻辑。

最后,<configuration_root>包含 mysettings.pywsgi.py.

我试过的:

我的Procfile应该是这样的(根据Heroku Docs):

web: gunicorn myapp.wsgi

使用此项目布局运行foreman start时,出现错误:

ImportError: Import by filename is not supported.

什么有效:

如果我将我的 Procfile 从它<git_repository_root>移到<git_repository_root>它在本地工作。推送到 Heroku(注意:Heroku 看到<git_repository_root>)后,我无法扩展任何工作程序/添加进程。我得到以下信息:

Scaling web dynos... failed
 !    No such process type web defined in Procfile.

我相信无论如何我都想要Procfile-<git_repository_root>那为什么它不起作用?我还尝试将其更改Procfile为: web: gunicorn myapp/myapp.wsgi

但没有运气。任何帮助将非常感激!

4

2 回答 2

4

将您的条目Procfile视为 bash 命令。你可以cd进入你的<django_project_root>然后运行服务器。

例如,你的Procfile(应该在你的<git_repository_root>)可能看起来像这样:

web: cd <django_project_root> && gunicorn 
     --env DJANGO_SETTINGS_MODULE=<configuration_root>.settings 
     <configuration_root>.wsgi
于 2015-06-19T13:19:34.133 回答
1

Procfile<git_repository_root>并使用:

web: gunicorn <django_project_root>.myapp:myapp

用你的应用程序的类名替换最后的“myapp”,大概它确实是“myapp”。

...并阅读错误消息:它告诉您不能通过app文件名 (myapp.wsgi) 导入您的工人类 (),所以当然说dirname/myapp.wsgi也行不通。您需要 Pythonmodule:class语法。

于 2013-08-07T05:16:13.577 回答