Debug Mode in Flask
Flask debug mode is designed to speed up development.
It usually provides:
- automatic reload when code changes
- interactive debugger with stack traces
Enabling debug mode
Option A: environment variable
export FLASK_DEBUG=1
flask runexport FLASK_DEBUG=1
flask runOption B: app.run
app.run(debug=True)app.run(debug=True)Why debug mode is dangerous in production
The interactive debugger can allow code execution if itβs exposed.
Rule of thumb:
- Debug mode is fine locally.
- Never enable debug mode on a public server.
In production, youβll use Gunicorn (or another WSGI server) and configuration-based logging.
Auto reload: what to know
When auto-reload is enabled, Flask may start your app twice (a reloader process + the actual app).
If your code does something at import time (like sending emails, starting a scheduler, etc.), it may run twice.
Best practice:
- keep side effects out of module import time
- put startup code behind guards or proper app factories
If this helped you, consider buying me a coffee β
Buy me a coffeeWas this page helpful?
Let us know how we did
