[英]Flask App on Heroku getting Application Error after deploy
I'm trying to run a Flask app with Gunicorn on Heroku.我正在尝试在 Heroku 上使用 Gunicorn 运行 Flask 应用程序。
This is my Procfile
:这是我的Procfile
:
web: gunicorn main: app
I have a file called main.py
.我有一个名为main.py
的文件。 Here is some of the code at the top:这是顶部的一些代码:
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)
My requirements.txt
:我的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
I'm getting this in my logs:我在我的日志中得到这个:
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]
The Procfile
looks to be right from what I've read online but otherwise I don't see anything wrong with this.根据我在网上阅读的内容, Procfile
看起来是正确的,但除此之外我没有发现任何问题。 Does anyone know what's going on with this?有谁知道这是怎么回事?
Remove the space between main
and app
:删除main
和app
之间的空格:
web: gunicorn main:app
Gunicorn wants a [WSGI_APP]
Gunicorn 想要一个[WSGI_APP]
Where
WSGI_APP
is of the pattern$(MODULE_NAME):$(VARIABLE_NAME)
.其中WSGI_APP
是模式$(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.变量名称指的是应该在指定模块中找到的 WSGI 可调用对象。
With the space, main:
and app
are read as separate arguments and Gunicorn receives an empty string as its VARIABLE_NAME
.对于空格, main:
和app
被读取为单独的 arguments 并且 Gunicorn 收到一个空字符串作为其VARIABLE_NAME
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.