尝试通过 uwsg 运行 flask app 时无法从 uwsgi 加载配置
unable to load configuration from uwsgi when attempting to run flask app via uwsg
我有以下 uwsgi app.ini 文件:
[uwsgi]
wsgi-file = wsgi.py
callable = app
socket = :5000
processes = 5
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true
wsgi.py内容:
from app import start
start()
最后 app.py 这是 Flask 应用程序本身(很长所以我只放相关的):
# instantiate the app
app = Flask(__name__, static_url_path='', static_folder='static', template_folder='templates')
app.config.from_object(__name__)
# enable CORS
CORS(app, resources={r'/*': {'origins': '*'}})
@app.route('/')
def index():
return render_template('index.html')
... all sort of methods here ...
def start():
print("STARTING !!!")
app.run(host='0.0.0.0')
if __name__ == '__main__':
start()
所有文件都在同一个文件夹中。
当我 运行 uwsgi app.ini
我得到这个:
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
unable to load configuration from uwsgi
这是为什么?
感谢您的帮助
快速浏览一下会发现两个问题。首先,uwsgi
和 app.run()
不兼容。当您使用 Flask 开发环境时,您可以使用后者。 uwsgi
想要保存 Flask 实例的对象。按照惯例,这是 app
,但您可以使用不同的名称(并配置 uwsgi
以查找不同的名称)。
这是第二期。 uwsgi
已加载 wsgi.py
(导致 app.run()
让您充分利用所看到的内容。然后它正在寻找 app
。但是因为您是从 app
,wsgi.py
拥有的 app
不是 Flask 实例。
最简单的做法是(在 uwsgi.ini 中)替换
file=wsgi.py
和
module=app:app
那应该绕过对 start()
的调用,让 uwsgi
处理事情。
我有以下 uwsgi app.ini 文件:
[uwsgi]
wsgi-file = wsgi.py
callable = app
socket = :5000
processes = 5
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true
wsgi.py内容:
from app import start
start()
最后 app.py 这是 Flask 应用程序本身(很长所以我只放相关的):
# instantiate the app
app = Flask(__name__, static_url_path='', static_folder='static', template_folder='templates')
app.config.from_object(__name__)
# enable CORS
CORS(app, resources={r'/*': {'origins': '*'}})
@app.route('/')
def index():
return render_template('index.html')
... all sort of methods here ...
def start():
print("STARTING !!!")
app.run(host='0.0.0.0')
if __name__ == '__main__':
start()
所有文件都在同一个文件夹中。
当我 运行 uwsgi app.ini
我得到这个:
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
unable to load configuration from uwsgi
这是为什么?
感谢您的帮助
快速浏览一下会发现两个问题。首先,uwsgi
和 app.run()
不兼容。当您使用 Flask 开发环境时,您可以使用后者。 uwsgi
想要保存 Flask 实例的对象。按照惯例,这是 app
,但您可以使用不同的名称(并配置 uwsgi
以查找不同的名称)。
这是第二期。 uwsgi
已加载 wsgi.py
(导致 app.run()
让您充分利用所看到的内容。然后它正在寻找 app
。但是因为您是从 app
,wsgi.py
拥有的 app
不是 Flask 实例。
最简单的做法是(在 uwsgi.ini 中)替换
file=wsgi.py
和
module=app:app
那应该绕过对 start()
的调用,让 uwsgi
处理事情。