Skip to content Skip to sidebar Skip to footer

Django Passing Html Objects Into Template As Plain Text

This feels like a really silly issue, but I'm confused by the behavior of django-zinnia, a blog creation module. When I test enter a plain text post, it appends each sentence with

Solution 1:

That's the default behavior for Django templates. Use {{ object_content|safe }} or {% autoescape off %} {{ object_content }} {% endautoescape %} (for multiple variables) to prevent html entities from being escaped.

Note that using the safe filter doesn't automatically mean the output is not escaped if you use another filter after it.

Solution 2:

Check the Zinnia's source code: https://github.com/Fantomas42/django-blog-zinnia/blob/master/zinnia/templates/zinnia/_entry_detail_base.html

It's using |safe template tag:

<divclass="entry-content">
    {{ object_content|safe }}
</div>

Post a Comment for "Django Passing Html Objects Into Template As Plain Text"