如何在django模板中添加注释

我想用一行来评论这个

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

作为Miles的回答, {% comment %}...{% endcomment %}用于多行注释,但是您也可以在同一行注释掉文本,如下所示:

 {# some text #} 

注释标签logging在https://docs.djangoproject.com/en/stable/ref/templates/builtins/#std:templatetag-comment

 {% comment %} this is a comment {% endcomment %} 

单行注释logging在https://docs.djangoproject.com/en/stable/topics/templates/#comments

 {# this won't be rendered #} 

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

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

把“#”放在你想评论的行之前