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
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),
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With