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

Django docs say that 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 a Context as a stack comes in handy in some custom template tags

However, there's no example for that. My suggestion: it's useful to render a subtemplate with a clean context ; but one can just use a new empty Context() object instead.

So, what's the use case?

Answers


The use case would be scoping, for example in loops and template inheritance.


Need Your Help

How to use lapply to specific indices of a list?

r list function indexing lapply

When using lapply to apply a function to a list, how would I do this for every other four elements in the list?

Nested ng-repeat doesn't appear angularjs

javascript angularjs ng-repeat

I'm trying to list out groups of items in angular using ng-repeat and then from those populating the groups items as well.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.