Can I suppress newlines after each template tag with Django's template engine?

后端 未结 5 2312
醉梦人生
醉梦人生 2021-02-19 08:05

In Rails ERB, you can suppress newlines by adding a trailing hyphen to tags:

    <% for @item in @items -%>
  • <%= @item %>
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 08:55

    For example:

      {% for obj in list %}
    • {{ obj|linebreaksbr|striptags }}
    • {% endfor %}

    Or this, which also strips whitespaces/tabs/etc, between HTML tags:

    {{ spaceless }}
    
      {% for obj in list %}
    • {{ obj }}
    • {% endfor %}
    {{ endspaceless }}

提交回复
热议问题