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 getRuntimeError: 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With