【发布时间】:2017-06-25 12:35:24
【问题描述】:
目前,我在我的 Django 模板中使用了一个 for 循环,如下所示:
{% for item in itemlist.items.all %}
<!-- do something -->
{% endfor %}
现在这对于遍历我的项目列表中的所有记录非常有用,但我想添加一个过滤器,例如,假设我的项目有一个价格,我只想遍历价格为的项目 > 5.我怎样才能做到这一点?有没有办法像 if 语句那样进行切片?
我尝试了类似的方法,但没有奏效”
{% for item in itemlist.items.all|price > 5 %}
感谢您的帮助!
【问题讨论】:
标签: html django templates django-templates