Skip to content

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 run
export FLASK_DEBUG=1
flask run

Option 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 coffee

Was this page helpful?

Let us know how we did