summaryrefslogtreecommitdiff
path: root/django/template/__init__.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-12-05 19:48:46 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-12-05 19:48:46 +0000
commitbe217bce53f4449708e20e2b71d9c8c4bf5b81eb (patch)
tree7408dfb16a27f2ddd907f6da1889b4e8645e54a0 /django/template/__init__.py
parent460ccfc04547decb2ebaf6cbf6a067b44a439ec4 (diff)
Template system now supports variables whose str() returns a Unicode object with non-ascii characters. Thanks, gabor
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4161 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template/__init__.py')
-rw-r--r--django/template/__init__.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py
index 5affafeba9..7718801684 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -742,7 +742,11 @@ class VariableNode(Node):
def encode_output(self, output):
# Check type so that we don't run str() on a Unicode object
if not isinstance(output, basestring):
- return str(output)
+ try:
+ return str(output)
+ except UnicodeEncodeError:
+ # If __str__() returns a Unicode object, convert it to bytestring.
+ return unicode(output).encode(settings.DEFAULT_CHARSET)
elif isinstance(output, unicode):
return output.encode(settings.DEFAULT_CHARSET)
else: