Michael
Michael

Reputation: 69

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 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?

Upvotes: 4

Views: 12525

Answers (3)

H.Rabiee
H.Rabiee

Reputation: 4837

Double check that you actually return the 'app' variable in your create_app.

Upvotes: 1

Aman Raheja
Aman Raheja

Reputation: 615

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.

Upvotes: 10

davidism
davidism

Reputation: 127190

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.

Upvotes: 1

Related Questions