Ticket #3529: context-doc.diff
File context-doc.diff, 1.4 KB (added by , 14 years ago) |
---|
-
django/template/context.py
74 74 super(Context, self).__init__(dict_) 75 75 76 76 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" 78 78 if not hasattr(other_dict, '__getitem__'): 79 79 raise TypeError('other_dict must be a mapping (dictionary-like) object.') 80 80 self.dicts.append(other_dict) -
docs/ref/templates/api.txt
281 281 ... 282 282 django.template.ContextPopException 283 283 284 In addition to ``push()`` and ``pop()``, the ``Context`` 285 object also defines an ``update()`` method. This works like ``push()`` 286 but takes a dictionary as an argument and pushes that dictionary onto 287 the 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 284 300 Using a ``Context`` as a stack comes in handy in some custom template tags, as 285 301 you'll see below. 286 302