Answers:
注释标签记录在https://docs.djangoproject.com/en/stable/ref/templates/builtins/#std:templatetag-comment
{% comment %} this is a comment {% endcomment %}
单行注释记录在https://docs.djangoproject.com/en/stable/topics/templates/#comments
{# this won't be rendered #}
与传统的html注释相反:
<!-- not so secret secrets -->
Django模板注释未在最终的html中呈现。因此,您可以随意在其中填充实现细节,如下所示:
多行:
{% comment %}
The other half of the flexbox is defined
in a different file `sidebar.html`
as <div id="sidebar-main">.
{% endcomment %}
单线:
{# jquery latest #}
{#
beware, this won't be commented out...
actually renders as regular body text on the page
#}
我发现这对于<a href="{% url 'view_name' %}"
尚未创建的视图特别有用。
{% extends "file.html" %}
标记,则应将其放在模板文件的最上方,甚至在{% comment %}
... 之前{% endcomment %}
,否则会出现<ExtendsNode: extends "file.html"> must be the first tag in the template
错误。我的意思是,如果有人想将多行注释放在模板顶部。