From b5adaec4c23e3fa8ab52da1c10eb52f775d02209 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 17 Mar 2008 14:21:09 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20#5884=20--=20Added=20better=20display?= =?UTF-8?q?=20error=20handling=20for=20template=20variables.=20Combined=20?= =?UTF-8?q?work=20from=20Karen=20Tracey=20and=20Thomas=20G=C3=BCttler.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@7260 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/__init__.py | 5 ++++- django/template/debug.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/django/template/__init__.py b/django/template/__init__.py index 29daa76eac..e60ff64ebf 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -129,7 +129,10 @@ class VariableDoesNotExist(Exception): self.params = params def __str__(self): - return self.msg % self.params + return unicode(self).encode('utf-8') + + def __unicode__(self): + return self.msg % tuple([force_unicode(p, errors='replace') for p in self.params]) class InvalidTemplateLibrary(Exception): pass diff --git a/django/template/debug.py b/django/template/debug.py index 008059c28f..c58c854858 100644 --- a/django/template/debug.py +++ b/django/template/debug.py @@ -75,7 +75,7 @@ class DebugNodeList(NodeList): raise except Exception, e: from sys import exc_info - wrapped = TemplateSyntaxError('Caught an exception while rendering: %s' % e) + wrapped = TemplateSyntaxError(u'Caught an exception while rendering: %s' % force_unicode(e, errors='replace')) wrapped.source = node.source wrapped.exc_info = exc_info() raise wrapped