score:2

Accepted answer

Jinja2 escapes all variables as a safety measure. The array of dictionaries you show is rendered by default as:

[{'f_name': 'Bruce Gradkowski', 'team': 'PIT', 'number': 5, 'position': 'QB', 'y': 99.79, 'x': 185.42}, {'f_name': 'Matthew Stafford', 'team': 'DET', 'number': 9, 'position': 'QB', 'y': 105.23, 'x': 190.5}]

Note how the quotes were converted into HTML entities.

To prevent escaping you can add the safe filter as follows:

{{ var_name|safe }}

Note that this only works because Javascript and Python happen to have a similar syntax for arrays and dictionaries.


Related Articles