Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent "&" from being converted to "&" in Jinja

Tags:

flask

jinja2

I am iterating over a dictionary in Python. The values that contain & are converted to &. How Do I stop that? It shows on the web page like this:

Hobbies & Leisure

My code looks like this:

{% for k,v  in vertical.iteritems() %}
    {value: '{{k}}', text: "{{v}}"},
{% endfor %}
like image 450
Tampa Avatar asked Sep 20 '12 22:09

Tampa


1 Answers

You can try the safe Jinja filter.

http://jinja.pocoo.org/docs/templates/#safe

{% for k, v in vertical.iteritems() %}
    {value: '{{ k|safe }}', text: "{{ v|safe }}"},
{% endfor %}
like image 111
FogleBird Avatar answered Nov 12 '22 11:11

FogleBird