【问题标题】:how to avoid extra spacing in template while using if endif condition in template django在模板django中使用if endif条件时如何避免模板中的额外间距
【发布时间】:2022-11-10 16:02:42
【问题描述】:

我正在从数据库中检索信息并使用 {%if%} 和 {%endif%} 条件,因此如果该字段为空白,则不会导致任何问题,但是当该字段没有任何值时,它会在适当位置创建一个新的空白行其中的样式看起来很糟糕 我看到一个答案 使用这个 {%if -%} {%- endif %}它不起作用并抛出我想要的所有错误如果字段为空白不要创建任何新的空白行并渲染第二个下面的行而不创建任何空格 任何建议都会有所帮助

【问题讨论】:

    标签: django django-models django-templates


    【解决方案1】:

    您可以使用内置的模板标签

    {% spaceless %}
        Space less content here
    {% endspaceless %}
    

    【讨论】:

      猜你喜欢
      • 2016-12-09
      • 2014-10-04
      • 2011-11-28
      • 2012-07-07
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      相关资源
      最近更新 更多