Is there a Django template tag that lets me set a context variable?
问题 I want to be able to set variables in a template to string values. I wrote a tag, but it doesn't seem to change the context. The intended use is: {% define "a string" as my_var %} Update (solved): class DefineNode(Node): def __init__(self, var, name): self.var = var self.name = name def __repr__(self): return "<DefineNode>" def render(self, context): context[self.name] = self.var return '' @register.tag def define(parser, token): """ Adds a name to the context for referencing an arbitrarily