Flask Debug Toolbar
Flask-DebugToolbar is a Flask extension that provides a customizable toolbar overlay for debugging web applications. It's an active project within the Pallets Community Ecosystem, currently at version 0.16.0, and releases updates periodically to maintain compatibility with Flask and Python.
Warnings
- breaking Version 0.16.0 drops support for Python 3.7. Applications running on Python 3.7 will need to upgrade their Python version to 3.8 or newer to use Flask-DebugToolbar 0.16.0 and above.
- breaking Version 0.16.0 requires Flask version 2.3.0 or higher. Older Flask versions are incompatible.
- gotcha Version 0.14.0 was released with a missing `packaging` dependency, causing an `ImportError`. This was fixed in 0.14.1.
- deprecated The `__version__` attribute has been removed from the library as of 0.16.0.
- gotcha The Debug Toolbar will only be displayed if `app.debug = True` is set and a `SECRET_KEY` is configured in `app.config`. Ensure `app.debug = True` is set *before* initializing `DebugToolbarExtension`.
- gotcha The toolbar requires a `<body>` tag in the HTML response to inject its content. It may not appear on pages returning plain strings or non-HTML content.
- gotcha The `Blinker` dependency was dropped in 0.16.0. If you have custom extensions or code relying on `Blinker` signals specifically related to the debug toolbar, this change might affect you, though it's generally an internal dependency removal.
Install
-
pip install flask-debugtoolbar
Imports
- DebugToolbarExtension
from flask_debugtoolbar import DebugToolbarExtension
Quickstart
from flask import Flask, render_template
from flask_debugtoolbar import DebugToolbarExtension
import os
app = Flask(__name__)
app.debug = True # Enable debug mode
app.config['SECRET_KEY'] = os.environ.get('FLASK_SECRET_KEY', 'a_very_secret_key_for_dev')
# Optional: Configure toolbar settings
# app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
toolbar = DebugToolbarExtension(app)
@app.route('/')
def index():
return '<body><h1>Hello, Flask!</h1></body>'
@app.route('/hello/<name>')
def hello(name):
return render_template('hello.html', name=name) # Ensure templates are in 'templates/' folder
# Example of running the app
# if __name__ == '__main__':
# # You would typically run with 'flask run --debug' or a WSGI server
# # For this quickstart, ensure FLASK_APP is set to your app file (e.g., 'app.py')
# # and then run 'flask run --debug'
# pass