1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | from django.template import defaulttags, VariableDoesNotExist, Variable
class ResolvingURLNode(defaulttags.URLNode):
def render(self, context):
original_view_name = self.view_name
try:
self.view_name = Variable(self.view_name).resolve(context)
except VariableDoesNotExist:
pass
ret = super(defaulttags.URLNode, self).render(context)
# restore view_name in case this node is reused (e.g in a loop) in
# which case the variable might resolve to something else in the next iteration)
self.view_name = original_view_name
return ret
defaulttags.URLNode = ResolvingURLNode
|
More like this
- A templatetag to insert the output of another view (or local URL) by jamesgpearce 2 years, 11 months ago
- Support for {% macro %} tags in templates, version 2 by mludvig 4 years, 9 months ago
- template tag for highlighting currently active page by adunar 3 years, 6 months ago
- CallTag - Just like include, but can pass parameters to it by limodou 5 years, 2 months ago
- Variable._resolve_lookup monkeypatch by showell 2 years, 6 months ago
Comments
It should be:
but besides that all cool.
#