我想用一句话来评论这一点:

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



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

当前回答

如果你想注释一些Django模板格式的代码,这种方法会很有帮助。

{#% include 'file.html' %#}(正确方式)

如果使用HTML注释注释,下面的代码仍然执行。

<!——{% include 'file.html' %}——>(错误方式)

其他回答

这是单行注释:

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

这是多行注释:

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

如果你想在{% extends…%} 在这种情况下最好使用

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

如果你想注释一些Django模板格式的代码,这种方法会很有帮助。

{#% include 'file.html' %#}(正确方式)

如果使用HTML注释注释,下面的代码仍然执行。

<!——{% include 'file.html' %}——>(错误方式)

使用{# #}符号,如下所示:

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

作为Miles的回答,{% comment %}…{% endcomment %}用于多行注释,但你也可以像这样注释掉同一行的文本:

{# some text #}