[Django]-How to put comments in Django templates?

426๐Ÿ‘

โœ…

As answer by Miles, {% comment %}...{% endcomment %} is used for multi-line comments, but you can also comment out text on the same line like this:

{# some text #}
๐Ÿ‘คVan Gale

169๐Ÿ‘

Comment tags are documented at https://docs.djangoproject.com/en/stable/ref/templates/builtins/#std:templatetag-comment

{% comment %} this is a comment {% endcomment %}

Single line comments are documented at https://docs.djangoproject.com/en/stable/topics/templates/#comments

{# this won't be rendered #}
๐Ÿ‘คMiles

32๐Ÿ‘

Using the {# #} notation, like so:

{# Everything you see here is a comment. It won't show up in the HTML output. #}
๐Ÿ‘คmipadi

9๐Ÿ‘

This way can be helpful if you want to comment some Django Template format Code.

{#% include 'file.html' %#} (Right Way)

Following code still executes if commented with HTML Comment.

<!-- {% include 'file.html' %} --> (Wrong Way)

๐Ÿ‘คRahul Shyokand

5๐Ÿ‘

This is single-line comments:

{# <p>This is comment</p> #}

This is multi-line comments:

{% comment "This is an optional note for comments" %}
    <p>This is comment</p>
    <p>This is comment</p>
    <p>This is comment</p>
{% endcomment %}

0๐Ÿ‘

this doesnโ€™t work if you want to comment before {% extends ... %}
In this case better use

<!--
# comment 1
# comment 2
# comment 3
-->
๐Ÿ‘คstats con chris

Leave a comment