Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't FLASK_APP find my factory function?

Tags:

python

flask

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?

like image 341
Michael Avatar asked Dec 13 '22 18:12

Michael


2 Answers

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.

like image 188
Aman Raheja Avatar answered Dec 17 '22 22:12

Aman Raheja


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.

like image 31
davidism Avatar answered Dec 17 '22 23:12

davidism