Which of the autoescape and safe filter tags is better to use?

I was looking for a way to unescape HTML in variables written in a Django template, and I found the answer here . So basically there are two ways to do this:

  • Set autoescapeto off:

    {% autoescape off %}{{ myHTMLstring }}{% endautoescape %}
    
  • Filter Usage safe:

    {{ myHTMLstring | safe }}
    

My question is which one is more appropriate for use (and in which context). I feel the filter safeis specific to Django, unlike autoescape, which seems to be also used in Jinja2. But what is your own way of thinking?

+3
source share

All Articles