Как поместить комментарии в шаблоны Django
Я хотел бы прокомментировать эту строку
{% if something.property %}
<table>
<tr>...
{% # this is a comment %}
{% if something.property %}
<table>
<tr>...
4 ответов
как ответ милями,{% comment %}...{% endcomment %}
используется для многострочных комментариев, но вы можете также закомментировать текст в той же строке, как это:
{# some text #}
теги комментариев задокументированы на 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 #}
С помощью {# #}
обозначение, например:
{# Everything you see here is a comment. It won't show up in the HTML output. #}
В отличие от традиционных HTML-комментарии такой:
<!-- not so secret secrets -->
комментарии к шаблону Django не отображаются в окончательном html. Таким образом, вы можете свободно заполнять детали реализации там так:
Multi-line:
{% comment %}
The other half of the flexbox is defined
in a different file orgchart-sidebar.html
as <div id="sidebar-main">.
{% endcomment %}
одну строку:
{# jquery latest #}
{#
beware, doesn't work...
actually renders as regular body text on the page
#}