Skip to main content

An admin page with a checkbox to enable the Django Debug Toolbar.

Project description

Debug Toolbar Checkbox

Demo

Install

First install the Django Debug Toolbar, if not already done.

$ pip install debug_toolbar_checkbox

In settings.py, add debug_toolbar_checkbox before django admin:

INSTALLED_APPS = [
    "debug_toolbar",
    "debug_toolbar_checkbox",
    "django.contrib.admin",
    ...,
]

In settings.py set a DEBUG_TOOLBAR_SETTINGS, or derive it from SECRET_KEY:

from hashlib import sha256
DEBUG_TOOLBAR_SECRET = sha256(b"djdt" + SECRET_KEY.encode("UTF-8")).hexdigest()

In settings.py configure the Debug Toolbar to check the secret in the cookie:

DEBUG_TOOLBAR_CONFIG = {
    "SHOW_TOOLBAR_CALLBACK": lambda request: DEBUG_TOOLBAR_SECRET in request.headers.get("cookie", "")
}

In urls.py add this before the path("admin/"):

path("admin/pages/", include("debug_toolbar_checkbox.urls")),

You may need to add include to the from django.urls import path line.

It may look like this:

from debug_toolbar.toolbar import debug_toolbar_urls
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("admin/pages/", include("debug_toolbar_checkbox.urls")),
    path("admin/", admin.site.urls),
] + debug_toolbar_urls()

Security

The activation is governed by the presence of a secret in a cookie. The cookie is set by some JavaScript (static file, publicly available). But the secret is only written in the admin page as a data attribute. The admin page is only accessible to superusers, so only superusers can query the page containing the secret.

If you're not OK with my sha256/concat to derive a new secret, feel free to replace it with a truly random secret.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_debug_toolbar_checkbox-0.1.2.tar.gz (78.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_debug_toolbar_checkbox-0.1.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file django_debug_toolbar_checkbox-0.1.2.tar.gz.

File metadata

File hashes

Hashes for django_debug_toolbar_checkbox-0.1.2.tar.gz
Algorithm Hash digest
SHA256 532406693bae530d9ec22788ee9943ba730d4db582e211811a0716b2eed19cb5
MD5 fad71501bbbe9b20e049e36f2309c3b6
BLAKE2b-256 5bd007ce5947f1773a41dc475a781c34b5463ec01b4652c96ea9e0dfdd67d69c

See more details on using hashes here.

File details

Details for the file django_debug_toolbar_checkbox-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_debug_toolbar_checkbox-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9657e39dea8e1fe1215be60fa33c855d999ec20b813e65310a786b1574b1acdc
MD5 d644d76162ac1f617ce54234631dccf4
BLAKE2b-256 4db91ffa2e981a0b9c0791d46ac84e1d6c1e3540e9cbb811ebfb5fb8e3d80cfb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page