| 1 |
Flask-DebugToolbar |
| 2 |
================== |
| 3 |
|
| 4 |
This extension adds a toolbar overlay to Flask applications containing useful information for debugging. |
| 5 |
|
| 6 |
.. image:: _static/example.gif |
| 7 |
|
| 8 |
Installation |
| 9 |
------------ |
| 10 |
|
| 11 |
Installing is simple with `pip`_:: |
| 12 |
|
| 13 |
$ pip install flask-debugtoolbar |
| 14 |
|
| 15 |
.. _pip: https://pip.pypa.io/ |
| 16 |
|
| 17 |
|
| 18 |
Usage |
| 19 |
----- |
| 20 |
|
| 21 |
Setting up the debug toolbar is simple:: |
| 22 |
|
| 23 |
from flask import Flask |
| 24 |
from flask_debugtoolbar import DebugToolbarExtension |
| 25 |
|
| 26 |
app = Flask(__name__) |
| 27 |
|
| 28 |
# the toolbar is only enabled in debug mode: |
| 29 |
app.debug = True |
| 30 |
|
| 31 |
# set a 'SECRET_KEY' to enable the Flask session cookies |
| 32 |
app.config['SECRET_KEY'] = '<replace with a secret key>' |
| 33 |
|
| 34 |
toolbar = DebugToolbarExtension(app) |
| 35 |
|
| 36 |
|
| 37 |
The toolbar will automatically be injected into HTML responses when debug mode |
| 38 |
is on. In production, setting ``app.debug = False`` will disable the toolbar. |
| 39 |
|
| 40 |
This extension also supports the Flask app factory pattern by separately |
| 41 |
creating the toolbar and later initializing it for an app:: |
| 42 |
|
| 43 |
toolbar = DebugToolbarExtension() |
| 44 |
# Then later on. |
| 45 |
app = create_app('the-config.cfg') |
| 46 |
toolbar.init_app(app) |
| 47 |
|
| 48 |
Configuration |
| 49 |
------------- |
| 50 |
|
| 51 |
The toolbar support several configuration options: |
| 52 |
|
| 53 |
==================================== ===================================== ========================== |
| 54 |
Name Description Default |
| 55 |
==================================== ===================================== ========================== |
| 56 |
``DEBUG_TB_ENABLED`` Enable the toolbar? ``app.debug`` |
| 57 |
``DEBUG_TB_HOSTS`` Whitelist of hosts to display toolbar any host |
| 58 |
``DEBUG_TB_ROUTES_HOST`` The host to associate with toolbar ``None`` |
| 59 |
routes (where its assets are served |
| 60 |
from), or the sentinel value `*` to |
| 61 |
serve from the same host as the |
| 62 |
current request (ie any host). This |
| 63 |
is only required if Flask is |
| 64 |
configured to use `host_matching`. |
| 65 |
``DEBUG_TB_INTERCEPT_REDIRECTS`` Should intercept redirects? ``True`` |
| 66 |
``DEBUG_TB_PANELS`` List of module/class names of panels enable all built-in panels |
| 67 |
``DEBUG_TB_PROFILER_ENABLED`` Enable the profiler on all requests ``False``, user-enabled |
| 68 |
``DEBUG_TB_TEMPLATE_EDITOR_ENABLED`` Enable the template editor ``False`` |
| 69 |
``DEBUG_TB_PROFILER_DUMP_FILENAME`` Filename of the profiler stats dump, ``None``, no dump will be written |
| 70 |
can be a ``str`` or a ``callable`` |
| 71 |
==================================== ===================================== ========================== |
| 72 |
|
| 73 |
To change one of the config options, set it in the Flask app's config like:: |
| 74 |
|
| 75 |
app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False |
| 76 |
|
| 77 |
|
| 78 |
Panels |
| 79 |
------ |
| 80 |
|
| 81 |
.. toctree:: |
| 82 |
|
| 83 |
panels |
| 84 |
license |
| 85 |
|
| 86 |
Contributing |
| 87 |
------------ |
| 88 |
|
| 89 |
Fork us `on GitHub <https://github.com/pallets-eco/flask-debugtoolbar>`_ |
| 90 |
|
| 91 |
Thanks |
| 92 |
------ |
| 93 |
|
| 94 |
This was based on the original `django-debug-toolbar`_. Thanks to `Michael van Tellingen`_ for the original development of this Flask extension, and to all the `individual contributors`_. |
| 95 |
|
| 96 |
.. _django-debug-toolbar: https://github.com/jazzband/django-debug-toolbar |
| 97 |
.. _Michael van Tellingen: https://github.com/mvantellingen |
| 98 |
.. _individual contributors: https://github.com/pallets-eco/flask-debugtoolbar/graphs/contributors |