3

So in Jinja2 I have this code:

<div id='posts'>
    <!-- Display all posts -->
    {% for p in posts %}
        <div class='post'>
            <h3>{{ p[1] }}</h3>
            {{ p[2] }}  
        </div>
    {% endfor %}
</div>  

The p[2] is what's important here. It's just a unicode string with the value of "<p>content</p> <b>bold</b>". I want it to display as html, but when I load the page, this is how it's displayed:

It it displaying improperly

However, when I view the page source, it looks like this:

&lt;p&gt;content&lt;/p&gt; &lt;b&gt;bold&lt;/b&gt;

All I want is for it to display as normal HTML. I have a feeling this is some weird encoding issue, and I know little about that. Any help is appreciated!

starscape
  • 2,739
  • 5
  • 26
  • 36

1 Answers1

6

This is autoescaping. It protects you against things like XSS injection.

If you're sure your content is safe, you can turn it off with

{% autoescape false %}...{% endautoescape %}
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895