[Django]-Difference between rendering {{ var }} and {{ var|safe }} in Django

5👍

The safe template filter allows html tags and entities in the content of var. Without it, your html will be escaped so you’ll see things like

<div> &nbsp;

etc on your page.

3👍

If var has html elements then the safe template filter will render it.

For example:

If var is hi

var|safe will be rendered hi
var will be displayed <b>hi</b>

1👍

Simply saying django’s safe method in template doesn’t render any html tags in template

Leave a comment