template = '<input type="hidden" name="csrfmiddlewaretoken" value="%s">'

def parse(self, parser):
    lineno = next(parser.stream).lineno
ctx_ref = jinja2.nodes.ContextReference()
node = self.call_method('_render_csrf', [ctx_ref], lineno=lineno)
return jinja2.nodes.CallBlock(node, [], [], [], lineno=lineno)

def _render_csrf(self, context, caller):
    csrf_token = context['csrf_token']
return jinja2.Markup(self.template % str(csrf_token))
csrf = CsrfExtension
Jinja Extension that has access to Context