Search code examples
pythonflaskpython-dotenv

Flask is not reacting to the FLASK_ENV variable setting


I am trying to activate debug mode in Flask.

What I have tried so far:

  • set FLASK_ENV=development directly in Windows cmd
  • pip installed python-dotenv successfully and set FLASKENV=development in .env file
  • ensured that there is no dotenv package globally and within virtual env
  • pip force uninstall/reinstall python-dotenv a few times
  • with python-dotenv, tried load_dotenv() and os.getenv('FLASK_ENV') and it shows that the value of FLASK_ENV is development

None of the above enabled the debug mode of Flask. FLASK_APP variable is correctly set and read though. Only by running Flask --debug run activates the debug mode.

Why is the FLASK_ENV variable not recognized by Flask?


Solution

  • As pointed out by ivvija: In Flask version 2.3.0, the FLASK_ENV environment variable (including the ENV config key and app.env property) has been removed.

    You should instead set FLASK_DEBUG=1, or set debug=True in your app.run() method or use the --debug option when running the flask run command to enable debug mode - any of these will work.