Author: SmileyChris
Date: 2010-11-23 18:36:36 -0600 (Tue, 23 Nov 2010)
New Revision: 14689
Modified:
django/trunk/django/template/context.py
django/trunk/docs/ref/templates/api.txt
Log:
Fixes #3529 -- more explicit documentation about Context.update. Thanks for the
patch, ggetzie.
Modified: django/trunk/django/template/context.py
===================================================================
--- django/trunk/django/template/context.py 2010-11-23 14:11:20 UTC (rev
14688)
+++ django/trunk/django/template/context.py 2010-11-24 00:36:36 UTC (rev
14689)
@@ -74,7 +74,7 @@
super(Context, self).__init__(dict_)
def update(self, other_dict):
- "Like dict.update(). Pushes an entire dictionary's keys and values
onto the context."
+ "Pushes other_dict to the stack of dictionaries in the Context"
if not hasattr(other_dict, '__getitem__'):
raise TypeError('other_dict must be a mapping (dictionary-like)
object.')
self.dicts.append(other_dict)
Modified: django/trunk/docs/ref/templates/api.txt
===================================================================
--- django/trunk/docs/ref/templates/api.txt 2010-11-23 14:11:20 UTC (rev
14688)
+++ django/trunk/docs/ref/templates/api.txt 2010-11-24 00:36:36 UTC (rev
14689)
@@ -281,6 +281,22 @@
...
django.template.ContextPopException
+In addition to ``push()`` and ``pop()``, the ``Context``
+object also defines an ``update()`` method. This works like ``push()``
+but takes a dictionary as an argument and pushes that dictionary onto
+the stack instead of an empty one.
+
+ >>> c = Context()
+ >>> c['foo'] = 'first level'
+ >>> c.update({'foo': 'updated'})
+ {'foo': 'updated'}
+ >>> c['foo']
+ 'updated'
+ >>> c.pop()
+ {'foo': 'updated'}
+ >>> c['foo']
+ 'first level'
+
Using a ``Context`` as a stack comes in handy in some custom template tags, as
you'll see below.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.