flask.cli.NoAppException:无法在模块“flaskr”中找到 Flask 应用程序或工厂。使用 "FLASK_APP=flaskr:name 指定一个

ash*_*ish 2 python flask

我正在使用 Flask 和来自http://flask.pocoo.org/docs/1.0/tutorial/factory/ 的教程构建一个 python web 应用程序。我正在从父目录运行烧瓶,但出现以下错误。

(venv) E:\python-code\python-web>flask run
 * Serving Flask app "flaskr" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 294-690-396
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello HTTP/1.1" 500 -
Traceback (most recent call last):
  File "e:\python-code\python-web\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
    raise value
  File "e:\python-code\python-web\venv\lib\site-packages\flask\cli.py", line 95, in find_best_app
    module=module.__name__
flask.cli.NoAppException: Failed to find Flask application or factory in module "flaskr". Use "FLASK_APP=flaskr:name to specify one.
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:44] "GET /hello?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:44] "GET /hello?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
Run Code Online (Sandbox Code Playgroud)

请帮忙。

我试过从 cli 运行 Flask 应用程序给出“没有名为flaskr 的模块”flask.cli.NoAppException: Failed to find application in module?

ash*_*ish 9

我发现了我的问题。我return app在我的代码中作为最后一个语句丢失了。抱歉给您带来困惑和歉意。

  • 你在 `create_app` func 的 `__init__.py` 中忘记了它,对吧?对于同一情况下的其他人,知道您在哪里忘记了它可能会很有趣。 (4认同)