[英]Failed to find Flask application or factory in module 'app'. Use 'FLASK_APP=app:name' to specify one
>>> flask run
* Serving Flask app 'app' (lazy loading)
* Environment: development
* Debug mode: on
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.
Error: Failed to find Flask application or factory in module 'app'. Use 'FLASK_APP=app:name' to specify one.
Getting this error when trying to make a package from my simple flask
app尝试从我的简单
flask
应用程序制作 package 时出现此错误
Also it can be another error:也可能是另一个错误:
Error: While importing 'app', an ImportError was raised.
And maybe it is也许是
>>> flask run
* Serving Flask app 'app' (lazy loading)
* Environment: development
* Debug mode: on
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.
Error: Could not import 'app.app'.
But I'm doing everything by the docs "Large Applications as Packages": https://flask.palletsprojects.com/en/2.0.x/patterns/packages/但我正在通过文档“Large Applications as Packages”做所有事情: https://flask.palletsprojects.com/en/2.0.x/patterns/packages/
In my case renaming app name from app
to another one helped.在我的情况下,将应用程序名称从
app
重命名为另一个会有所帮助。
Maybe it was some kind of namespace error, because my package was ./app
and Flask app object
variable in __init__.py
was named app
(Despite Miguel in his tutorial did it the same way)也许这是某种命名空间错误,因为我的 package 是
./app
和Flask app object
变量在__init__.py
中被命名为app
(尽管在他的教程中)
In general, while developing web applications you have to be careful with names like wsgi
- they can be reserved.通常,在开发 web 应用程序时,您必须小心使用
wsgi
之类的名称 - 它们可以保留。
I am executing set FLASK_APP=module
, set FLASK_ENV=development
, pip install -e.
我正在执行
set FLASK_APP=module
, set FLASK_ENV=development
, pip install -e.
and flask run
commands in the first (upper) module
directory.和
flask run
在第一个(上) module
目录中运行命令。
And maybe you only need to revert changes from flask doc tutorial returning to the file structure without __init__.py
and with normal app.py
.也许您只需要将更改从flask 文档教程返回到没有
__init__.py
和普通app.py
的文件结构。 After that delete all __pycache__
folders and repeat this tutorial again之后删除所有
__pycache__
文件夹并再次重复本教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.