291

I would like to comment this with a line:

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



{% # this is a comment %}
{% if something.property %}
    <table>
        <tr>...

6 Answers 6

443

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 #}
Sign up to request clarification or add additional context in comments.

1 Comment

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 <ExtendsNode: extends "file.html"> 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.
179

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

Comments

33

Using the {# #} notation, like so:

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

Comments

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)

Comments

7

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

1 Comment

Why was the same answer reposted 13 years later? How is this helpful?
0

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

<!--
# comment 1
# comment 2
# comment 3
-->

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.