小编典典

如何在Django模板中添加注释

django

我想用一行评论

{% if something.property %}
    <table>
        <tr>...



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

阅读 647

收藏
2020-04-03

共2个答案

小编典典

作为Miles的答案,{% comment %}...{% endcomment %}它用于多行注释,但是你也可以像这样在同一行上注释掉文本:

{# some text #}
2020-04-03
小编典典

注释标签记录在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 #}
2020-04-03