Persistent Session Debugging with Django Debug Toolbar

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
MIDDLEWARE_CLASSES = [
    ...
    "django.contrib.sessions.middleware.SessionMiddleware",
    "debug_toolbar.middleware.DebugToolbarMiddleware",
    ...
]

def show_debug_toolbar(request):
    """Shows the debug toolbar based on the debug arg in the URL.
    
    ?debug=on - turns debugging on in the current session
    ?debug=off - turns debugging off in the current session
    """
    if DEBUG:
        debug = request.GET.get("debug", None)
        if debug == "on":
            request.session["debug"] = True
        elif debug == "off" and "debug" in request.session:
            del request.session["debug"]
        return "debug" in request.session
    
DEBUG_TOOLBAR_CONFIG = {
    "SHOW_TOOLBAR_CALLBACK": show_debug_toolbar,
}

More like this

  1. Custom panel showing your project svn revision on djano debug toolbar by coulix 5 years, 6 months ago
  2. Globs for INTERNAL_IPS by kcarnold 5 years, 1 month ago
  3. CurrentSessionIDMiddleware by troolee 3 years, 8 months ago
  4. Include entire networks in INTERNAL_IPS setting by pmclanahan 5 years, 1 month ago
  5. Smart Spaceless by btaylordesign 3 years ago

Comments

(Forgotten your password?)