Mar 06, 2017

How To Install Django Debug Toolbar

Alejandro León González

@alex_ln_gz

The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.

For the installation of the Django Debug Toolbar you need to have a django project where you can use pip in a Virtual Environment or without them. If you wan’t use pip, you can get the code of this component from here (https://github.com/jazzband/django-debug-toolbar) and put it in your django project path. But is more easy the pip installation and we will focus on this.

For installation we recommend use the virtual env and execute this command:

pip install django-debug-toolbar

The configuration of this component is simple, but because most of the configuration must be done in the core of the settings of the project, we recommend to do it independently.

First, in your general project urls.py, enter this code:

from django.conf import settings
from django.conf.urls import include, url

if settings.DEBUG:
   import debug_toolbar
   urlpatterns += [
       url(r'^__debug__/', include(debug_toolbar.urls)),
   ]

Take care with the “imports” because it’s possible that you duplicate some of this.

In the settings.py we enter our independent conf for this component, like this:

DEBUG = True

if DEBUG:
   INTERNAL_IPS = ('127.0.0.1', 'localhost',)
   MIDDLEWARE_CLASSES += (
       'debug_toolbar.middleware.DebugToolbarMiddleware',
   )

   INSTALLED_APPS += (
       'debug_toolbar',
   )

   DEBUG_TOOLBAR_PANELS = [
       'debug_toolbar.panels.versions.VersionsPanel',
       'debug_toolbar.panels.timer.TimerPanel',
       'debug_toolbar.panels.settings.SettingsPanel',
       'debug_toolbar.panels.headers.HeadersPanel',
       'debug_toolbar.panels.request.RequestPanel',
       'debug_toolbar.panels.sql.SQLPanel',
       'debug_toolbar.panels.staticfiles.StaticFilesPanel',
       'debug_toolbar.panels.templates.TemplatesPanel',
       'debug_toolbar.panels.cache.CachePanel',
       'debug_toolbar.panels.signals.SignalsPanel',
       'debug_toolbar.panels.logging.LoggingPanel',
       'debug_toolbar.panels.redirects.RedirectsPanel',
   ]

   DEBUG_TOOLBAR_CONFIG = {
       'INTERCEPT_REDIRECTS': False,
   }

The INTERNAL_IPS conf is valid for a local development environment, if your dev env is different, you just change this field with your valid conf.

This is the default conf and if you want see more options you can see this page:

https://django-debug-toolbar.readthedocs.io/en/stable/configuration.html

Note: Is very important that you have the close body tag ( </body> ) in your base template for the Django Debug Toolbar is showing.

This component has a variety of panels that can be added through the configuration, these panels show different information related to http requests / responses and other relevant debug data, in this url you can see all differents default panels and you can learn how to use and configure it. http://django-debug-toolbar.readthedocs.io/en/stable/panels.html

The result will be a toolbar in your screen right place with debug information like this:

 

And here's a screenshot of the toolbar in action:


Leave a comment