【发布时间】:2010-10-17 17:19:34
【问题描述】:
我想用一行来评论这个
{% if something.property %}
<table>
<tr>...
{% # this is a comment %}
{% if something.property %}
<table>
<tr>...
【问题讨论】:
我想用一行来评论这个
{% if something.property %}
<table>
<tr>...
{% # this is a comment %}
{% if something.property %}
<table>
<tr>...
【问题讨论】:
评论标签记录在https://docs.djangoproject.com/en/stable/ref/templates/builtins/#std:templatetag-comment
{% comment %} this is a comment {% endcomment %}
单行 cmets 记录在 https://docs.djangoproject.com/en/stable/topics/templates/#comments
{# this won't be rendered #}
【讨论】:
正如 Miles 的回答,{% comment %}...{% endcomment %} 用于多行 cmets,但您也可以像这样在同一行注释掉文本:
{# some text #}
【讨论】:
{% extends "file.html" %} 标签,你应该把它放在模板文件的最顶部,甚至在{% comment %}...{% endcomment %} 之前,否则你会得到一个<ExtendsNode: extends "file.html"> must be the first tag in the template 错误。我是说如果有人想将多行 cmets 放在模板的顶部。
使用{# #} 符号,如下所示:
{# Everything you see here is a comment. It won't show up in the HTML output. #}
【讨论】:
如果你想注释一些 Django 模板格式的代码,这种方式会很有帮助。
{#% include 'file.html' %#}(正道)
如果使用 HTML 注释进行注释,以下代码仍会执行。
<!-- {% include 'file.html' %} -->(走错路了)
【讨论】: