【问题标题】:Trouble to deploy flask application on heroku在heroku上部署烧瓶应用程序的麻烦
【发布时间】:2020-11-27 17:03:37
【问题描述】:

我无法在 heroku 上部署我的烧瓶应用程序, 我的目录树如下所示:

├── app
│   ├── errors.py
│   ├── forms.py
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── models.py
│   ├── __pycache__
│   ├── routes.py
│   ├── static
│   ├── storage.db
│   └── templates
├── migrations
├── Procfile
├── README.md
├── requirements.txt
├── run.py
└── runtime.txt
  $ cat runtime
  python-3.8.5

  $ cat Procfile 
  web: gunicorn: app:app

我对 Procfile 的配置很困惑,我应该调用 run.py(我用来在本地使用“flask run”调用的存档)还是 app(init.py 所在的文件夹调用flask实例和sql_alchemy实例)?

不管怎样,两种配置都返回了下面的错误:


$ heroku 日志 --tail

heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `gunicorn: app:app`
app[web.1]: bash: gunicorn:: command not found
heroku[web.1]: Process exited with status 127
heroku[web.1]: State changed from starting to crashed

gunicorn 已经在 requirements.py 中配置了

【问题讨论】:

  • 假设您的 run.py 是您的应用程序的入口点,并且您已将烧瓶实例命名为 app ,您的 Procfile 应类似于 web: gunicorn run:app
  • 谢谢@Aditya,它成功了!你为什么不在下面回答而不是评论?然后我会标记为最佳答案,它应该可以帮助其他人:)
  • 不客气:)。老实说,我不知道为什么我没有写它作为答案?????但无论如何,我现在写它作为答案,以便其他人也可以从中受益。

标签: flask heroku deployment gunicorn


【解决方案1】:

假设 your run.py 是您的应用程序的入口点,并且您已将烧瓶实例命名为 app ,您的 Procfile 应如下所示:

web: gunicorn run:app

这是因为在您的 Procfile 中,第一个参数必须是您运行网站的主文件或入口文件的名称,第二个参数是您的烧瓶实例本身的名称。至少是 gunicorn 和 heroku 的情况。

【讨论】:

    猜你喜欢
    • 2011-06-11
    • 2014-11-26
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多