简体   繁体   中英

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

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/

In my case renaming app name from app to another one helped.

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)

In general, while developing web applications you have to be careful with names like wsgi - they can be reserved.

I am executing set FLASK_APP=module , set FLASK_ENV=development , pip install -e. and flask run commands in the first (upper) module directory.

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 . After that delete all __pycache__ folders and repeat this tutorial again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM