Printing Variables in a Flask Template

flask, jinja2, printing, python, templates

Solution

The syntax for outputting variables is {{var}}, {% %} is for blocks and other directives. However, it sounds like the variable wasn't passed to the template. Check for that.

If you're doing a lot of debugging, try Flask-DebugToolbar, it'll print out all the variables that got passed to your template so you don't have to muck around with print statements like this. Useful stuff.

Problem

I have a variable in my code that is buried deep in some legacy code. Rather than spend all day searching for it, I'd like to just print out the variable from within the jinja template. Is that possible? I tried `{% print var %}`, but that didn't seem to do anything.

Original source