Skip to content

Commit 5701e1f

Browse files
kmikerobhudson
authored andcommitted
Print non-iterable template context layers as-is
Signed-off-by: Rob Hudson <rob@cogit8.org>
1 parent 065162d commit 5701e1f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

debug_toolbar/panels/template.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,20 @@ def content(self):
8383

8484
context_list = []
8585
for context_layer in context_data.dicts:
86-
for key, value in context_layer.items():
87-
# Replace any request elements - they have a large
88-
# unicode representation and the request data is
89-
# already made available from the Request Vars panel.
90-
if isinstance(value, http.HttpRequest):
91-
context_layer[key] = '<<request>>'
92-
# Replace the debugging sql_queries element. The SQL
93-
# data is already made available from the SQL panel.
94-
elif key == 'sql_queries' and isinstance(value, list):
95-
context_layer[key] = '<<sql_queries>>'
96-
# Replace LANGUAGES, which is available in i18n context processor
97-
elif key == 'LANGUAGES' and isinstance(value, tuple):
98-
context_layer[key] = '<<languages>>'
86+
if hasattr(context_layer, 'items'):
87+
for key, value in context_layer.items():
88+
# Replace any request elements - they have a large
89+
# unicode representation and the request data is
90+
# already made available from the Request Vars panel.
91+
if isinstance(value, http.HttpRequest):
92+
context_layer[key] = '<<request>>'
93+
# Replace the debugging sql_queries element. The SQL
94+
# data is already made available from the SQL panel.
95+
elif key == 'sql_queries' and isinstance(value, list):
96+
context_layer[key] = '<<sql_queries>>'
97+
# Replace LANGUAGES, which is available in i18n context processor
98+
elif key == 'LANGUAGES' and isinstance(value, tuple):
99+
context_layer[key] = '<<languages>>'
99100
try:
100101
context_list.append(pformat(context_layer))
101102
except UnicodeEncodeError:

0 commit comments

Comments
 (0)