我正在使用flask构建一个python web应用程序,并遵循http://flask.pocoo.org/docs/1.0/tutorial/factory/的教程。我从父目录运行flask,但得到以下错误。
(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 -请帮帮忙。
我试过Running Flask app from cli gives "no module named flaskr"和flask.cli.NoAppException: Failed to find application in module?
发布于 2019-03-18 01:00:50
我找到了我的问题。我遗漏了return app作为我代码中的最后一条语句。很抱歉给你带来了困惑和道歉。
发布于 2021-02-04 16:47:55
我得到了那个错误
flask.cli.NoAppException flask.cli.NoAppException:在模块"flaskr“中找不到Flask应用程序或工厂。使用"FLASK_APP=flaskr:name“指定一个。
我尝试了所有答案,在将函数名称从create_function更改为create_app后,问题得到了解决
发布于 2019-05-20 08:28:33
你的应用程序目录没有正确命名吗?例如,如果您编写了FLASK_APP=flaskr,但您的项目名称是其他名称,则会出现此错误。另外,如果项目在教程中命名为flaskr,那么flaskr/flaskr/__init__.py文件中的内容是什么?
https://stackoverflow.com/questions/55199434
复制相似问题