In Django templates, `Context` is a stack. What for?

Django docs say Context object is a stack:

 from django.template import Context c = Context() c['a'] = 1 c.push() # Make a new Context level c['a'] = 2 print(repr(c)) # [{'a': 1}, {'a': 2}] 

Also the docs say

Using context as a stack comes in handy in some custom template tags.

However, there is no example for this. My suggestion: it is useful to make outsoles with a clean context; but instead, you can simply use the new empty Context() object.

So what is the use case?

+4
source share
1 answer

A use case will have a scope, for example, in loops and template inheritance.

+1
source

All Articles