Ticket #3529: context-doc.diff

File context-doc.diff, 1.4 KB (added by ggetzie, 14 years ago)

Moved the documentation for Context.update to its own block

  • django/template/context.py

     
    7474        super(Context, self).__init__(dict_)
    7575
    7676    def update(self, other_dict):
    77         "Like dict.update(). Pushes an entire dictionary's keys and values onto the context."
     77        "Pushes other_dict to the stack of dictionaries in the Context"
    7878        if not hasattr(other_dict, '__getitem__'):
    7979            raise TypeError('other_dict must be a mapping (dictionary-like) object.')
    8080        self.dicts.append(other_dict)
  • docs/ref/templates/api.txt

     
    281281    ...
    282282    django.template.ContextPopException
    283283
     284In addition to ``push()`` and ``pop()``, the ``Context``
     285object also defines an ``update()`` method. This works like ``push()``
     286but takes a dictionary as an argument and pushes that dictionary onto
     287the stack instead of an empty one.
     288
     289    >>> c = Context()
     290    >>> c['foo'] = 'first level'
     291    >>> c.update({'foo': 'updated'})
     292    {'foo': 'updated'}
     293    >>> c['foo']
     294    'updated'
     295    >>> c.pop()
     296    {'foo': 'updated'}
     297    >>> c['foo']
     298    'first level'
     299
    284300Using a ``Context`` as a stack comes in handy in some custom template tags, as
    285301you'll see below.
    286302
Back to Top