就像HTML或者Python,Django模板语言同样提供代码注释。 注释使用 {# #} :

{# This is a comment #}

注释的内容不会在模板渲染时输出。

用这种语法的注释不能跨越多行。 这个限制是为了提高模板解析的性能。 在下面这个模板中,输出结果和模板本身是 完全一样的(也就是说,注释标签并没有被解析为注释):

This is a {# this is not
a comment #}
test.

如果要实现多行注释,可以使用“ {% comment %}“ 模板标签,就像这样:

{% comment %}
This is a
multi-line comment.
{% endcomment %}