Ticket #15791: do_not_call_in_templates.diff

File do_not_call_in_templates.diff, 2.2 KB (added by Ethan Jucovy, 13 years ago)
  • docs/ref/templates/api.txt

     
    195195    * A variable can only be called if it has no required arguments. Otherwise,
    196196      the system will return an empty string.
    197197
     198    * Occasionally you may want to turn off this feature, and tell the template
     199      system to leave a variable un-called no matter what.  To disable this feature,
     200      set a ``do_not_call_in_templates`` attribute on the callable variable.  The
     201      template system then will act as if your variable is not callable.
     202
    198203    * Obviously, there can be side effects when calling some variables, and
    199204      it'd be either foolish or a security hole to allow the template system
    200205      to access them.
     
    207212
    208213      To prevent this, set an ``alters_data`` attribute on the callable
    209214      variable. The template system won't call a variable if it has
    210       ``alters_data=True`` set. The dynamically-generated
     215      ``alters_data=True`` set, and will instead replace the variable with an
     216      empty string, unconditionally.  The dynamically-generated
    211217      :meth:`~django.db.models.Model.delete` and
    212218      :meth:`~django.db.models.Model.save` methods on Django model objects get
    213219      ``alters_data=True`` automatically. Example::
  • django/template/base.py

     
    692692                                ):
    693693                            raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute
    694694                if callable(current):
    695                     if getattr(current, 'alters_data', False):
     695                    if getattr(current, 'do_not_call_in_templates', False):
     696                        pass
     697                    elif getattr(current, 'alters_data', False):
    696698                        current = settings.TEMPLATE_STRING_IF_INVALID
    697699                    else:
    698700                        try: # method call (assuming no args required)
Back to Top