GreenTurtle
GreenTurtle

Reputation: 880

Why does django parse tags in commented HTML code?

Why does django parse tags in sections of the template that are commented out with HTML comments?

Upvotes: 4

Views: 397

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477160

Because it is still part of the content you write in the response. It is not said that HTML comment has no meaning. For example one can write JavaScript code that inspects the HTML code, and process these comments, for example as directives how to change the DOM. Parts commented out in HTML (between <!-- and -->) are still part of the DOM, and a parser thus can interprete these.

In order to comment out parts in the template, such that these are not passed to the response, you can use:

{# … #}

or you can write the content between the {% comment %} and {% endcomment %} template tags [Django-doc]:

{% comment %}
    …
{% endcomment %}

Upvotes: 5

Related Questions