Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does django parse tags in commented HTML code?

Tags:

django

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

like image 891
MarMat Avatar asked Oct 23 '25 21:10

MarMat


1 Answers

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 %}
like image 178
Willem Van Onsem Avatar answered Oct 26 '25 11:10

Willem Van Onsem