3

My settings.py file looks like-

import os

# This file contains Django settings for lower environments that use the Django Debug Toolbar.
# Currently those envronments are DEV and QA.
from core.settings import *  # noqa: F403

# We need the ability to disable debug_toolbar for regression tests.
DEBUG = os.getenv('DEBUG_MODE', 'FALSE').upper() == 'TRUE'

def toolbar_callback(request):
    return DEBUG


DEBUG_TOOLBAR_CONFIG = {
    "SHOW_TOOLBAR_CALLBACK": toolbar_callback,
}

INSTALLED_APPS += ['debug_toolbar', ]  # noqa: F405
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware', ]  # noqa: F405

I want to exclude certain pages from loading debug toolbar. The reason being that the pages have a lot of SQL and debug toolbar is taking too long to load and hence page results in a timeout

Mahak Malik
  • 165
  • 2
  • 11

1 Answers1

1

The value of SHOW_TOOLBAR_CALLBACK determines if debug toolbar ought to be used on the page. Therefore you can exclude specific URLs/URL-patterns by evaluating the request path. For example with generator expression:

if DEBUG:
    patterns = [
        "/foo/bar/",
        "/baz/",
    ]
    DEBUG_TOOLBAR_CONFIG = {
        'SHOW_TOOLBAR_CALLBACK': lambda request: not any(p in request.path for p in patterns),
    }