How to get a list of current variables from Jinja 2 template?

Viewed 25451

If I return a Jinja2 template like so: return render_response('home.htm', **context)

How do then get a list of the variables in context from within the template?

3 Answers

I found @Garrett's answer to be a bit more complex than what I wanted. I found that I can easily inspect the context by adding a clone of the context to the context itself:

contextCopy = dict(context)
context['all'] = contextCopy

And then pretty printing that into my Jinja template with <pre>{{ all|pprint }}</pre>.

Related