Django Debug Toolbar

6.3.0 · active · verified Thu Apr 09

Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/response in Django applications. It is actively maintained by the Django Commons organization, with new releases typically coming out every few months, often tied to Django's release cycle and Python version support. The current version is 6.3.0.

Warnings

Install

Imports

Quickstart

To quickly set up Django Debug Toolbar, first install the package. Then, modify your Django project's `settings.py` by adding `'debug_toolbar'` to `INSTALLED_APPS` and `'debug_toolbar.middleware.DebugToolbarMiddleware'` to `MIDDLEWARE`. Crucially, configure `INTERNAL_IPS` to include your development machine's IP address(es) for the toolbar to be visible. Finally, add the debug toolbar's URLs to your project's `urls.py`, typically conditional on `settings.DEBUG` being `True`.

# settings.py
import os

DEBUG = True # Essential for debug_toolbar to appear

INSTALLED_APPS = [
    # ... your other apps
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    
    "debug_toolbar", # Add debug_toolbar to your INSTALLED_APPS
]

MIDDLEWARE = [
    # ... Django's default middleware ...
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "debug_toolbar.middleware.DebugToolbarMiddleware", # Place early in middleware list
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    # ... your custom middleware ...
]

# Configure INTERNAL_IPS for the toolbar to show up
INTERNAL_IPS = [
    "127.0.0.1",
    "::1", # IPv6 localhost
    # If running in Docker, WSL, or remotely, add your development machine's IP, e.g.,
    # "172.17.0.1", # Common for Docker host
    # os.environ.get("YOUR_DEV_IP", ""), # Dynamic IP example
]

# Optional: Customize toolbar behavior (e.g., disable panels)
DEBUG_TOOLBAR_CONFIG = {
    "DISABLE_PANELS": [
        "debug_toolbar.panels.redirects.RedirectsPanel" # Example: disable redirects panel
    ],
    "SHOW_TOOLBAR_CALLBACK": "debug_toolbar.utils.show_toolbar_callback",
}


# urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings

if settings.DEBUG:
    import debug_toolbar # Only import if DEBUG is True
    urlpatterns = [
        path("__debug__/", include(debug_toolbar.urls)),
        path("admin/", admin.site.urls),
        # ... your other app paths ...
    ]
else:
    urlpatterns = [
        path("admin/", admin.site.urls),
        # ... your other app paths ...
    ]

view raw JSON →