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()andos.getenv('FLASK_ENV')and it shows that the value of FLASK_ENV isdevelopment
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?
As pointed out by ivvija: In Flask version 2.3.0, the
FLASK_ENVenvironment variable (including theENVconfig key andapp.envproperty) has been removed.You should instead set
FLASK_DEBUG=1, or setdebug=Truein yourapp.run()method or use the--debugoption when running theflask runcommand to enable debug mode - any of these will work.