在 heroku 上部署 flask 应用程序时遇到问题

Trouble to deploy flask application on heroku

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

├── 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 运行在本地调用的存档”)还是app([=所在的文件夹) 23=]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

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