[Django]-Why does django parse tags in commented HTML code?

4👍

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 %}

Leave a comment