- Author:
- brianjaystanley
- Posted:
- October 19, 2011
- Language:
- Python
- Version:
- 1.3
- Score:
- 1 (after 1 ratings)
When using django debug toolbar, I like to be able to turn debugging on and off without having to edit my settings file. This callback makes that possible. Add ?debug=on
to the URL to turn debugging on. It will remain on in the current session until you turn it off with ?debug=off
.
Make sure your session middleware comes before your debug toolbar middleware.
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
- Browser-native date input field by kytta 4 weeks, 1 day ago
- Generate and render HTML Table by LLyaudet 1 month, 1 week ago
- My firs Snippets by GutemaG 1 month, 1 week ago
- FileField having auto upload_to path by junaidmgithub 2 months, 2 weeks ago
- LazyPrimaryKeyRelatedField by LLyaudet 2 months, 3 weeks ago
Comments
Please login first before commenting.