python - Set global template variable in template tag -


I know there are reference processors that can do this, but I want to set the global template variable in the template tag. So far I have tried this: class> SetNode (template.Node): def __init __ (self, key, nodalist): self.key = key self.nodelist = nodelist def render , Context): reference to d in the value = self.nodelist.render (reference) reference: d [self.key] = return value ''

Ie repeat all the references and Set the variable, but it does not work. Can anyone explain how to do this? For example, base.html:

  {{my_var}} {# I set this variable in child template #} {% block content%} {% endblock%}   

child.html:

  {% extended 'base.html'%} {% block content%} {% my_var%} Hello {% endset%} { Here's an old-but-one-goi: tag. The code is self-explanatory.  

Note that its use (possibly) takes some of your business logic into your template, but sometimes it's OK.

Comments