275

I would like to comment this with a line:

{% if something.property %}
    <table>
        <tr>...



{% # this is a comment %}
{% if something.property %}
    <table>
        <tr>...
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Alex. S.
  • 143,260
  • 19
  • 55
  • 62

6 Answers6

421

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
  • 43,536
  • 9
  • 71
  • 81
  • 20
    True, but if you have an `{% extends "file.html" %}` tag you should put that on the very top of the template file even before the `{% comment %}`...`{% endcomment %}`, otherwise you'll get an ` must be the first tag in the template` error. I am saying that in case someone wants to place the multi-line comments on the top of the template. – pebox11 Jun 19 '15 at 02:03
167

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
  • 31,360
  • 7
  • 64
  • 74
32

Using the {# #} notation, like so:

{# Everything you see here is a comment. It won't show up in the HTML output. #}
mipadi
  • 398,885
  • 90
  • 523
  • 479
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
  • 1,255
  • 10
  • 17
4

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 %}
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
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
  • 178
  • 1
  • 10