What is export for FLASK_APP and FLASK_ENV?

Asked

Viewed 56 times

1

I’m learning flask now and understand that every time I run my application, I need to run before:

export FLASK_APP=app.py
export FLASK_ENV=development

I just memorized that I need to do this, but I don’t understand why. Where am I exporting these commands? What is their function? I really need to do it every time (even on a project I’ve done it before)?

1 answer

2


These are environment variables that help Flask understand how to behave.

The first,FLASK_APP can be left empty and then it will search for "app" or "wsgi" (with or without the ".py" at the end, ie can be a file or a module) but you can also:

  • A file/module in the current directory, for example FLASK_APP=src/hello;
  • A module to be imported, such as FLASK_APP=hello.web;
  • A specific instance within the module, something like FLASK_APP=hello:app2 or
  • Directly execute the Factory create_app() and even with passing parameters, like FLASK_APP=hello:create_app('dev')".

These examples I have sinned from flask documentation.

Already the FLASK_ENVdefines the type of execution environment of the project, the values recognized are two, "Production" and "Development", if nothing is defined it will use "Production" by default.

And its function is to turn on/off certain behaviors within Flask and extensions, for example, using "Development" will turn on debug mode ("DEBUG").

Browser other questions tagged

You are not signed in. Login or sign up in order to post.