Heroku 上的 Flask 应用程序在部署后出现应用程序错误
Flask App on Heroku getting Application Error after deploy
我正在尝试 运行 在 Heroku 上使用 Gunicorn 开发 Flask 应用程序。
这是我的 Procfile
:
web: gunicorn main: app
我有一个名为 main.py
的文件。这是顶部的一些代码:
from flask import Flask, redirect, url_for, render_template, request, session, flash
from datetime import timedelta, datetime
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.secret_key = "{Secret Key}"
app.permanent_session_lifetime = timedelta(minutes=10)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.sqlite3'
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
....
if __name__ == "__main__":
db.create_all()
app.run(debug=True)
我的requirements.txt
:
click==7.1.2
Flask==1.1.2
Flask-SQLAlchemy==2.4.4
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
SQLAlchemy==1.3.22
Werkzeug==1.0.1
我在我的日志中得到这个:
2020-12-31T00:00:05.879585+00:00 app[web.1]: Failed to parse '' as an attribute name or function call.
2020-12-31T00:00:05.880396+00:00 app[web.1]: [2020-12-31 00:00:05 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-12-31T00:00:05.887417+00:00 app[web.1]: Failed to parse '' as an attribute name or function call.
2020-12-31T00:00:05.888296+00:00 app[web.1]: [2020-12-31 00:00:05 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-12-31T00:00:06.139402+00:00 app[web.1]: [2020-12-31 00:00:06 +0000] [4] [INFO] Shutting down: Master
2020-12-31T00:00:06.139670+00:00 app[web.1]: [2020-12-31 00:00:06 +0000] [4] [INFO] Reason: App failed to load.
2020-12-31T00:00:06.291109+00:00 heroku[web.1]: Process exited with status 4
2020-12-31T00:00:06.360098+00:00 heroku[web.1]: State changed from up to crashed
2020-12-31T00:00:12.000891+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" [some extra stuff]
2020-12-31T00:00:12.118356+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" [some extra stuff]
Procfile
从我在网上阅读的内容来看似乎是正确的,但除此之外我没有发现任何问题。有人知道这是怎么回事吗?
删除main
和app
之间的space:
web: gunicorn main:app
Where WSGI_APP
is of the pattern $(MODULE_NAME):$(VARIABLE_NAME)
. The module name can be a full dotted path. The variable name refers to a WSGI callable that should be found in the specified module.
对于 space,main:
和 app
被读取为单独的参数,Gunicorn 接收一个空字符串作为其 VARIABLE_NAME
。
我正在尝试 运行 在 Heroku 上使用 Gunicorn 开发 Flask 应用程序。
这是我的 Procfile
:
web: gunicorn main: app
我有一个名为 main.py
的文件。这是顶部的一些代码:
from flask import Flask, redirect, url_for, render_template, request, session, flash
from datetime import timedelta, datetime
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.secret_key = "{Secret Key}"
app.permanent_session_lifetime = timedelta(minutes=10)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.sqlite3'
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
....
if __name__ == "__main__":
db.create_all()
app.run(debug=True)
我的requirements.txt
:
click==7.1.2
Flask==1.1.2
Flask-SQLAlchemy==2.4.4
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
SQLAlchemy==1.3.22
Werkzeug==1.0.1
我在我的日志中得到这个:
2020-12-31T00:00:05.879585+00:00 app[web.1]: Failed to parse '' as an attribute name or function call.
2020-12-31T00:00:05.880396+00:00 app[web.1]: [2020-12-31 00:00:05 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-12-31T00:00:05.887417+00:00 app[web.1]: Failed to parse '' as an attribute name or function call.
2020-12-31T00:00:05.888296+00:00 app[web.1]: [2020-12-31 00:00:05 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-12-31T00:00:06.139402+00:00 app[web.1]: [2020-12-31 00:00:06 +0000] [4] [INFO] Shutting down: Master
2020-12-31T00:00:06.139670+00:00 app[web.1]: [2020-12-31 00:00:06 +0000] [4] [INFO] Reason: App failed to load.
2020-12-31T00:00:06.291109+00:00 heroku[web.1]: Process exited with status 4
2020-12-31T00:00:06.360098+00:00 heroku[web.1]: State changed from up to crashed
2020-12-31T00:00:12.000891+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" [some extra stuff]
2020-12-31T00:00:12.118356+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" [some extra stuff]
Procfile
从我在网上阅读的内容来看似乎是正确的,但除此之外我没有发现任何问题。有人知道这是怎么回事吗?
删除main
和app
之间的space:
web: gunicorn main:app
Where
WSGI_APP
is of the pattern$(MODULE_NAME):$(VARIABLE_NAME)
. The module name can be a full dotted path. The variable name refers to a WSGI callable that should be found in the specified module.
对于 space,main:
和 app
被读取为单独的参数,Gunicorn 接收一个空字符串作为其 VARIABLE_NAME
。