Heroku 上的 Flask:无法在 运行 脚本中找到属性 <app_name>:错误 H10 desc="App crashed"

Flask on Heroku: failed to find attribute <app_name> in run script: error H10 desc="App crashed"

这是我的第一个(正确的)Flask 应用程序,本质上是 Corey Schafer Flask YouTube 教程的扩展。

根文件夹:

Procfile:

web: gunicorn --bind 0.0.0.0:$PORT run:bsstg

run.py:

from bsstg import create_app

app = create_app()

if __name__ == '__main__':
    app.run(debug=False)

bsstg 文件夹:

[![bsstg folder contents][2]][2]
[2]: https://i.stack.imgur.com/DXnw3.png

完整错误列表:

2021-08-21T14:57:45.224522+00:00 heroku[web.1]: State changed from starting to up
2021-08-21T14:57:47.689647+00:00 app[web.1]: /app/.heroku/python/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
2021-08-21T14:57:47.689676+00:00 app[web.1]: warnings.warn(FSADeprecationWarning(
2021-08-21T14:57:47.691540+00:00 app[web.1]: /app/.heroku/python/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
2021-08-21T14:57:47.691542+00:00 app[web.1]: warnings.warn(FSADeprecationWarning(
2021-08-21T14:57:48.011870+00:00 app[web.1]: Failed to find attribute 'bsstg' in 'run'.
2021-08-21T14:57:48.012140+00:00 app[web.1]: [2021-08-21 14:57:48 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-08-21T14:57:48.012928+00:00 app[web.1]: Failed to find attribute 'bsstg' in 'run'.
2021-08-21T14:57:48.013176+00:00 app[web.1]: [2021-08-21 14:57:48 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-08-21T14:57:48.130969+00:00 app[web.1]: [2021-08-21 14:57:48 +0000] [4] [INFO] Shutting down: Master
2021-08-21T14:57:48.131000+00:00 app[web.1]: [2021-08-21 14:57:48 +0000] [4] [INFO] Reason: App failed to load.
2021-08-21T14:57:48.194499+00:00 heroku[web.1]: Process exited with status 4
2021-08-21T14:57:48.281397+00:00 heroku[web.1]: State changed from up to crashed
2021-08-21T14:57:55.591575+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bsstg.herokuapp.com request_id=3418126a-a6f6-4e31-93c9-0c688104f8e3 fwd="109.153.222.121" dyno= connect= service= status=503 bytes= protocol=https
2021-08-21T14:57:56.000370+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bsstg.herokuapp.com request_id=c9360a07-edaa-4857-b5d6-4dcd445adbf7 fwd="109.153.222.121" dyno= connect= service= status=503 bytes= protocol=https

错误

Failed to find attribute 'bsstg' in 'run'"

(bsstg 是我的应用程序的名称和它所在的文件夹)是我用作问题标题的名称,但也许这一直让我绕圈子。现在两天了,非常感谢任何指点。

你的Procfile几乎可以肯定是错误的:

web: gunicorn --bind 0.0.0.0:$PORT run:bsstg

这个运行s Gunicorn as a web process (one that accepts incoming HTTP and HTTPS requests). Gunicorn expects a WSGI app as an argument。您正在传递 run:bsstg,它告诉 Gunicorn 运行 run 模块中的任何 bsstg

这会导致您看到的错误:

Failed to find attribute 'bsstg' in 'run'

run.py中没有bsstg; WSGI 应用程序称为 app。尝试将其更改为

web: gunicorn --bind 0.0.0.0:$PORT run:app

然后提交并重新部署。