From the documentation, I understand that the context object is a stack. Then what are push()
and update()
doing with respect to this code segment? It is stated in the doc that push()
and update()
are similar but update()
takes a dictionary as argument. Then why are we using them simultaneously here?
import django.template
import django.template.loader
def render(name, *values):
ctx = django.template.Context()
for d in values:
ctx.push()
ctx.update(d)
t = django.template.loader.get_template(name)
return str(t.render(ctx))
Also, what is the need of having context object as a stack?
Edit : I went through the doc again and found the flatten()
function which flattens all the levels in the stack to make them comparable.