【发布时间】:2014-04-30 07:17:49
【问题描述】:
用 nginx+uWSGI 成功部署了一个最小的 Flask 应用程序,我被这个难住了。
from flask import Flask
from bsfdash.users import users
from bsfdash.dashboard import dashboard
from bsfdash.customs import customs
from bsfdash import app
if __name__ == '__main__':
app.register_blueprint(users)
app.register_blueprint(dashboard)
app.register_blueprint(customs)
app.run()
为了确认我的 nginx 和 uWSGI 设置正确,我使用返回“Hi!”的 @app.route('/') 使用简单的“Hello World”Flask 应用程序进行了测试。 - 它按预期工作。
但是,上面显示的应用程序使用 localhost:5000 上的烧瓶网络服务器按预期工作 - 但通过 uWSGI 调用时不会路由 @dashboard.route('/') 蓝图。
我发现关于使用 uWSGI 部署包含蓝图的模块化 Flask 应用程序的信息为零。
为什么这个应用程序可以作为 Flask 网络服务器工作,但通过 uWSGI 却脑死了?
【问题讨论】:
-
但是当
uwsgi导入app时,它不会运行__main__块;移动您的蓝图注册。将if测试中的那些移出。 -
谢谢@MartijnPieters 将蓝图注册从 if 测试中移出,现在可以使用了!
标签: nginx flask url-routing uwsgi