Installation

  1. Install package.
pip install django-debug-toolbar
  1. In settings make sure that static files is set up and APP_DIRS in TEMPLATES is set to True.
  2. Install in settings:
# Debug Toolbar
INSTALLED_APPS += ["debug_toolbar"]
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
INTERNAL_IPS = ["127.0.0.1"]
DEBUG_TOOLBAR_CONFIG = {"ROOT_TAG_EXTRA_ATTRS": "hx-preserve"} # used by HTMX
  1. Add the URLs:
urlpatterns = [
     path("__debug__/", include("debug_toolbar.urls")),
]
  1. if using HTMX add following to base.html template:
{% if debug %}
      window.addEventListener("load", (event) => {
        if (typeof window.htmx !== "undefined") {
            htmx.on("htmx:afterSettle", function(detail) {
                if (
                    typeof window.djdt !== "undefined"
                    && detail.target instanceof HTMLBodyElement
                ) {
                    djdt.show_toolbar();
                }
            });
        }
      });
    {% endif %}