Skip to content

What is the best way to programmatically know what module to set FLASK_APP to? #4660

Answered by davidism
brettcannon asked this question in Q&A
Discussion options

You must be logged in to vote

Flask itself has some detection for when FLASK_APP isn't set that will probably serve you well enough.

  1. Look for a file called wsgi.py or app.py in the current directory.
  2. Within that, look for a variable called app or application, if it's a Flask object return it.
  3. Look for any variable that is an instance of Flask and return that.
  4. Look for a function called create_app or make_app. Call it without arguments, if it returns a Flask object return it.

I'd suggest extending this to looking in __init__.py and app.py files within the packages in the current project, something VS Code should be able to figure out which Flask itself can't. And since you're not actually executing code, look for var…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@brettcannon
Comment options

@ThiefMaster
Comment options

Comment options

You must be logged in to vote
2 replies
@brettcannon
Comment options

@davidism
Comment options

Answer selected by brettcannon
Comment options

You must be logged in to vote
1 reply
@davidism
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants