Code

Ticket #3529: context-doc.diff

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

Moved the documentation for Context.update to its own block

Line 
1Index: django/template/context.py
2===================================================================
3--- django/template/context.py  (revision 14649)
4+++ django/template/context.py  (working copy)
5@@ -74,7 +74,7 @@
6         super(Context, self).__init__(dict_)
7 
8     def update(self, other_dict):
9-        "Like dict.update(). Pushes an entire dictionary's keys and values onto the context."
10+        "Pushes other_dict to the stack of dictionaries in the Context"
11         if not hasattr(other_dict, '__getitem__'):
12             raise TypeError('other_dict must be a mapping (dictionary-like) object.')
13         self.dicts.append(other_dict)
14Index: docs/ref/templates/api.txt
15===================================================================
16--- docs/ref/templates/api.txt  (revision 14649)
17+++ docs/ref/templates/api.txt  (working copy)
18@@ -281,6 +281,22 @@
19     ...
20     django.template.ContextPopException
21 
22+In addition to ``push()`` and ``pop()``, the ``Context``
23+object also defines an ``update()`` method. This works like ``push()``
24+but takes a dictionary as an argument and pushes that dictionary onto
25+the stack instead of an empty one.
26+
27+    >>> c = Context()
28+    >>> c['foo'] = 'first level'
29+    >>> c.update({'foo': 'updated'})
30+    {'foo': 'updated'}
31+    >>> c['foo']
32+    'updated'
33+    >>> c.pop()
34+    {'foo': 'updated'}
35+    >>> c['foo']
36+    'first level'
37+
38 Using a ``Context`` as a stack comes in handy in some custom template tags, as
39 you'll see below.
40