代码之家  ›  专栏  ›  技术社区  ›  Alex. S.

如何在Django模板中放置注释

  •  154
  • Alex. S.  · 技术社区  · 17 年前

    我想用一句话来评论这一点

    {% if something.property %}
        <table>
            <tr>...
    
    
    
    {% # this is a comment %}
    {% if something.property %}
        <table>
            <tr>...
    
    4 回复  |  直到 8 年前
        1
  •  371
  •   Van Gale    17 年前

    作为迈尔斯的回答, {% comment %}...{% endcomment %} 用于多行注释,但您也可以对同一行上的文本进行注释,如下所示:

    {# some text #}
    
        2
  •  141
  •   Miles    11 年前
        3
  •  28
  •   mipadi    17 年前

    使用 {# #}

    {# Everything you see here is a comment. It won't show up in the HTML output. #}
    
        4
  •  18
  •   Kermit    5 年前

    与传统的 html注释

    <!-- not so secret secrets -->
    

    Django模板注释

    多行:

    {% 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' %}" .

        5
  •  4
  •   Thusitha Deepal    7 年前

    {% comment %} All inside this tags are treated as comment {% endcomment %}
    
        6
  •  4
  •   Rahul Shyokand    6 年前

    {#% include 'file.html' %#} (正确的方式)

    如果使用HTML注释进行注释,则仍会执行以下代码。

    <!-- {% include 'file.html' %} --> (走错路)

    推荐文章