rubik
rubik

Reputation: 9104

Django's template variable gets interpreted as HTML

When DEBUG=True a variable containing HTML is just printed in the template and not interpeted as HTML. This is the correct behavior.

On the other hand, when DEBUG=False (just changing this) the variable's content is interpreted as HTML and I cannot understand why. I'm not using the safe filter.

My template is as follows:

  <pre id="copy-source-{{ forloop.counter }}">
    <code>{{ code }}</code>
  </pre>

In one case, code happens to be HTML code, specifically:

<a href="blabla"><img src="bblabla" /></a>

and the page displays the image instead of the code, even if it's inside a pre-code!?

Upvotes: 1

Views: 188

Answers (1)

Alexey Sidash
Alexey Sidash

Reputation: 441

Try this

{% autoescape off %}
    {{var_containing_html}}
{% endautoescape %}

I hope this will help. Good luck.

P.S. Also see docs

Upvotes: 2

Related Questions