Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixes #3529 -- more explicit documentation about Context.update. Than…

…ks for the patch, ggetzie.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4c519867904918d8cdf2ded91af3e87bd1c02664 1 parent ff7c243
@SmileyChris SmileyChris authored
Showing with 17 additions and 1 deletion.
  1. +1 −1  django/template/
  2. +16 −0 docs/ref/templates/api.txt
2  django/template/
@@ -74,7 +74,7 @@ def __init__(self, dict_=None, autoescape=True, current_app=None, use_l10n=None)
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.')
16 docs/ref/templates/api.txt
@@ -281,6 +281,22 @@ If you ``pop()`` too much, it'll raise
+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.

0 comments on commit 4c51986

Please sign in to comment.
Something went wrong with that request. Please try again.