为什么我的 python 文件 returns 无法在 uwsgi flask 中加载应用程序?

Why my python file returns unable to load app in uwsgi flask?

我已阅读以下与 uwsgi 相关的问题,有趣的是,到目前为止没有任何帮助:

似乎我需要将应用程序导入为 application,因为 uWSGI 试图找到应用程序变量。

from tf_api import create_app as application

if __name__ == "__main__":
    application = application()
    application.run()
else:
    print("---------------------->", __name__)
    application = application()

当我运行下面的命令时:

uwsgi --socket 0.0.0.0:80 --protocol=tcp -w wsgi:app

它转到 else 部分并输出:

----------------------> wsgi
2020-02-20 14:25:22,168 [tf_core] Initialized! [testing=False]
2020-02-20 14:25:22,176 [tf_api] {"msg": "Initialized! Testing: False", "logger_name": "tf_api", "log_level": "DEBUG", "timestamp": "2020-02-20T14:25:22.176664"}
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 27143, cores: 1)

应用程序打印了一些日志,然后它打印 no app loaded!

当我application.run(host='0.0.0.0') 放入 else 时,似乎应用程序启动 运行ning 但在烧瓶默认端口 5000 上不在 uWSGI:

----------------------> wsgi
2020-02-20 14:36:57,333 [tf_core] Initialized! [testing=False]
2020-02-20 14:36:57,339 [tf_api] {"msg": "Initialized! Testing: False", "logger_name": "tf_api", "log_level": "DEBUG", "timestamp": "2020-02-20T14:36:57.339723"}
 * Serving Flask app "tf_api" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
2020-02-20 14:36:57,405 [werkzeug]  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
2020-02-20 14:36:57,406 [werkzeug]  * Restarting with stat
unable to load configuration from /usr/local/lib/python3.6/dist-packages/tf_api/uwsgi

但是它 给出了与 unable to load configuration from 相关的错误。 created_appreturnsapp。你们认为在 uswgi 中找不到 app 的原因是什么?

当我在 uwsgi 命令中使用 -w wsgi:app 时,我不得不重命名以下代码:

application = application()

至:

app = application()

没有 app.run(),因为 uWSGI 本身运行 flask 应用程序,不需要它。