简体   繁体   中英

Why can't FLASK_APP find my factory function?

I am trying to reconfigure an existing Flask app with an application factory to be installed with setup.py .

Currently, with my non-installable package, I use a file called wsgi.py and point FLASK_APP at that.

from example.factory import create_app
app = create_app()
export FLASK_APP=wsgi.py
flask run

However, if I try to point Flask directly at the factory in the installed package, I get RuntimeError: Failed to find application in module "example.factory" . I found this pattern in the examples in the Flask repository .

export FLASK_APP="example.factory:create_app()"
flask run  # doesn't find the app

Why does the wsgi.py method work while the direct method fails?

I kept my flask application name as flask.py .

Changing this to flaskfile.py or any other name but not flask alone worked for me

Maybe flask is a keyword.

You need to use the docs and examples that match the version of Flask that you're using.

You're looking at the tutorial from the master branch. But you're using the current Flask release, which doesn't support detecting app factories yet. You still need to use your current method of pointing at a file that creates the app until 1.0 is released.

仔细检查您是否确实在create_app中返回了“ app”变量。

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