Skip to content

Commit 29775b0

Browse files
brokensealrobhudson
authored andcommitted
Added configurable HTML tag to attach toolbar to
Signed-off-by: Rob Hudson <[email protected]>
1 parent 5237ee7 commit 29775b0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ The debug toolbar has two settings that can be set in `settings.py`:
114114
off is useful when you have large template contexts, or you have template
115115
contexts with lazy datastructures that you don't want to be evaluated.
116116

117+
* `TAG`: If set, this will be the tag to which debug_toolbar will attach the
118+
debug toolbar. Defaults to 'body'.
119+
117120
Example configuration::
118121

119122
def custom_show_toolbar(request):
@@ -124,6 +127,7 @@ The debug toolbar has two settings that can be set in `settings.py`:
124127
'SHOW_TOOLBAR_CALLBACK': custom_show_toolbar,
125128
'EXTRA_SIGNALS': ['myproject.signals.MySignal'],
126129
'HIDE_DJANGO_SQL': False,
130+
'TAG': 'div',
127131
}
128132

129133
`debugsqlshell`

debug_toolbar/middleware.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@ def __init__(self):
3737

3838
# Set method to use to decide to show toolbar
3939
self.show_toolbar = self._show_toolbar # default
40+
41+
# The tag to attach the toolbar to
42+
self.tag= u'</body>'
43+
4044
if hasattr(settings, 'DEBUG_TOOLBAR_CONFIG'):
4145
show_toolbar_callback = settings.DEBUG_TOOLBAR_CONFIG.get(
4246
'SHOW_TOOLBAR_CALLBACK', None)
4347
if show_toolbar_callback:
4448
self.show_toolbar = show_toolbar_callback
4549

50+
tag = settings.DEBUG_TOOLBAR_CONFIG.get('TAG', None)
51+
if tag:
52+
self.tag = u'</' + tag + u'>'
53+
4654
def _show_toolbar(self, request):
4755
if not request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS \
4856
or request.is_ajax() or not settings.DEBUG:
@@ -83,6 +91,9 @@ def process_response(self, request, response):
8391
for panel in self.debug_toolbars[request].panels:
8492
panel.process_response(request, response)
8593
if response['Content-Type'].split(';')[0] in _HTML_TYPES:
86-
response.content = replace_insensitive(smart_unicode(response.content), u'</body>', smart_unicode(self.debug_toolbars[request].render_toolbar() + u'</body>'))
94+
response.content = replace_insensitive(
95+
smart_unicode(response.content),
96+
self.tag,
97+
smart_unicode(self.debug_toolbars[request].render_toolbar() + self.tag))
8798
del self.debug_toolbars[request]
8899
return response

0 commit comments

Comments
 (0)