模板的注释

iris.Django的注释我们使用大括号+#来实现注释:{# 注释内容 #}

单行注释使用 {# 这只能注释单行 #},多行注释使用 {% comment %}这里注释很多行{% endcomment %}

示例:

空单行注释

{# #}

单行注释

{# testing single line comment #}

用有效标签填充单行注释

{# testing single line comment {% if thing %}{% endif %} #}

用无效标签填充单行注释

{# testing single line comment {% if thing %} #}

用无效语法填充单行注释

{# testing single line comment {% if thing('') %}wow{% endif %} #}

空块注释

{% comment %}{% endcomment %}

填充文本单行块注释

{% comment %}filled block comment {% endcomment %}

空多行块注释

{% comment %}


{% endcomment %}

阻止带有其他标签的注释

{% comment %}
  {{ thing_goes_here }}
  {% if stuff %}do stuff{% endif %}
{% endcomment %}

阻止其中带有无效标签的注释

{% comment %}
  {% if thing %}
{% endcomment %}

使用无效语法阻止注释

{% comment %}
  {% thing('') %}
{% endcomment %}

注释之间的常规标签,以确保其在词法分析器中不会中断

{% if hello %}
{% endif %}
after if
{% comment %}All done{% endcomment %}