【问题标题】:empty block is not working with endif inside a loop空块不适用于循环内的 endif
【发布时间】:2019-07-23 09:25:53
【问题描述】:

我正在构建一个仪表板,其中空白内容具有不同的视图,因此用户不会查看空白区域。

它适用于没有 if 块for 循环,例如

 {% for dashboard in dashboard_list %} 


    some content

            {% empty %} no data {% endfor %}

现在

{% for todo in todo_list %}
                            {% if todo.complete %}{% else %} some content



                            {% endif %}  {% empty %} content when its empty  {% endfor %}  

它不工作并且不显示“无数据”

【问题讨论】:

  • 确保您拥有dashboard_list 而不是没有。此外,如果你有 todo_list 条件,其中你有 dashboard_list 的空块

标签: django python-3.x for-loop django-templates


【解决方案1】:

当然,它不起作用... {% empty %} 仅在 todo_list 中没有任何内容时调用,如果每个循环传递都不会返回任何内容,则不会调用它。

要解决该问题,您应该遍历一个已过滤且不包含任何完整项目的列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 2018-03-13
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多