Yes it is possible. Today I had the same question and I got the following template tag. I wanted the functionality to support the django like syntax, so it was migrated from the django url template tag.
from django import template import webapp2 register = template.Library() def uri_for(parser, token): """Webapp2 uri_for django template tag""" bits = token.split_contents() if len(bits) < 2: raise template.TemplateSyntaxError("'%s' takes at least one argument (path to a view)" % bits[0]) view_name = bits[1] as_var = None if len(bits) >= 2 and bits[-2] == 'as': as_var = bits[-1] return UriForNode(view_name, as_var) uri_for = register.tag(uri_for) class UriForNode(template.Node): """Uri for node""" def __init__(self, uri, as_var=None): self.uri = uri self.as_var = as_var def render(self, context): view = webapp2.uri_for(self.uri) if self.as_var: context[self.as_var] = view return '' return view
Jesse source share