mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
magic-removal: Removed SilentVariableFailure exception, in favor of a silent_variable_failure attribute on the exception. Updated docs and added unit tests.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1680 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -147,10 +147,10 @@ Method lookups are slightly more complex than the other lookup types. Here are
|
||||
some things to keep in mind:
|
||||
|
||||
* If, during the method lookup, a method raises an exception, the exception
|
||||
will be propagated, unless the exception subclasses
|
||||
``django.core.template.SilentVariableFailure``. If the exception
|
||||
subclasses ``SilentVariableFailure``, the variable will render as an
|
||||
empty string. Example::
|
||||
will be propagated, unless the exception has an attribute
|
||||
``silent_variable_failure`` whose value is ``True``. If the exception
|
||||
*does* have a ``silent_variable_failure`` attribute, the variable will
|
||||
render as an empty string. Example::
|
||||
|
||||
>>> t = Template("My name is {{ person.first_name }}.")
|
||||
>>> class PersonClass3:
|
||||
@@ -162,15 +162,21 @@ some things to keep in mind:
|
||||
...
|
||||
AssertionError: foo
|
||||
|
||||
>>> from django.core.template import SilentVariableFailure
|
||||
>>> class SilentAssertionError(SilentVariableFailure): pass
|
||||
>>> class SilentAssertionError(Exception):
|
||||
... silent_variable_failure = True
|
||||
>>> class PersonClass4:
|
||||
... def first_name(self):
|
||||
... raise SilentAssertionError, "foo"
|
||||
... raise SilentAssertionError
|
||||
>>> p = PersonClass4()
|
||||
>>> t.render(Context({"person": p}))
|
||||
"My name is ."
|
||||
|
||||
Note that ``django.core.exceptions.ObjectDoesNotExist``, which is the
|
||||
base class for all Django database API ``DoesNotExist`` exceptions, has
|
||||
``silent_variable_failure = True``. So if you're using Django templates
|
||||
with Django model objects, any ``DoesNotExist`` exception will fail
|
||||
silently.
|
||||
|
||||
* A method call will only work if the method has no required arguments.
|
||||
Otherwise, the system will move to the next lookup type (list-index
|
||||
lookup).
|
||||
|
||||
Reference in New Issue
Block a user