Fixed #3441: VariableDoesNotExist is now a bit lazier about rendering its error message. Thanks, Brian Harring.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4461 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2007-02-06 13:59:24 +00:00
parent 04c4a031ba
commit b5f9176115
1 changed files with 8 additions and 2 deletions

View File

@ -117,8 +117,14 @@ class TemplateDoesNotExist(Exception):
pass pass
class VariableDoesNotExist(Exception): class VariableDoesNotExist(Exception):
pass
def __init__(self, msg, params=()):
self.msg = msg
self.params = params
def __str__(self):
return self.mgs % self.params
class InvalidTemplateLibrary(Exception): class InvalidTemplateLibrary(Exception):
pass pass
@ -660,7 +666,7 @@ def resolve_variable(path, context):
try: # list-index lookup try: # list-index lookup
current = current[int(bits[0])] current = current[int(bits[0])]
except (IndexError, ValueError, KeyError): except (IndexError, ValueError, KeyError):
raise VariableDoesNotExist, "Failed lookup for key [%s] in %r" % (bits[0], current) # missing attribute raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bits[0], current)) # missing attribute
except Exception, e: except Exception, e:
if getattr(e, 'silent_variable_failure', False): if getattr(e, 'silent_variable_failure', False):
current = settings.TEMPLATE_STRING_IF_INVALID current = settings.TEMPLATE_STRING_IF_INVALID