diff options
| author | qingfeng <qingfenghello@gmail.com> | 2014-07-22 01:38:34 +0800 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-07-26 18:03:19 +0200 |
| commit | 08451f17d08486055542daecdcc3be1779f0815b (patch) | |
| tree | 4f5c1882eee336848ad44e26d62e3db0a527d96d | |
| parent | 90faa196f67863370a4682ecfd053e189cd46705 (diff) | |
Fixed #23060 -- Prevented UnicodeDecodeError in debug templatetag
| -rw-r--r-- | django/template/defaulttags.py | 2 | ||||
| -rw-r--r-- | tests/template_tests/tests.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index ceeb7f3335..2ce8f3633c 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -87,7 +87,7 @@ class CycleNode(Node): class DebugNode(Node): def render(self, context): from pprint import pformat - output = [pformat(val) for val in context] + output = [force_text(pformat(val)) for val in context] output.append('\n\n') output.append(pformat(sys.modules)) return ''.join(output) diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index 84b6592f57..0d83f38950 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -10,6 +10,7 @@ import warnings from django import template from django.conf import settings +from django.contrib.auth.models import Group from django.core import urlresolvers from django.template import (base as template_base, loader, Context, RequestContext, Template, TemplateSyntaxError) @@ -499,6 +500,15 @@ class TemplateRegressionTests(TestCase): with self.assertRaises(urlresolvers.NoReverseMatch): t.render(Context({})) + def test_debug_tag_non_ascii(self): + """ + Test non-ASCII model representation in debug output (#23060). + """ + Group.objects.create(name="清風") + c1 = Context({"objs": Group.objects.all()}) + t1 = Template('{% debug %}') + self.assertIn("清風", t1.render(c1)) + # Set ALLOWED_INCLUDE_ROOTS so that ssi works. @override_settings(MEDIA_URL="/media/", STATIC_URL="/static/", |
