Mik*_*keN 3 django django-templates
我想要Django模板页面中的“ ifgt”模板标签的效果:
{%ifgt forloop.counter 10%}<!---special greater than 10 code--!>{%endif%}
Run Code Online (Sandbox Code Playgroud)
如果只需要大于,可以使用以下简单代码段(将其放入app / templatetags / greaterthan.py中):
from django import template
register = template.Library()
@register.filter
def gt(a, b):
return a > b
Run Code Online (Sandbox Code Playgroud)
并在模板中:
{% load greterthan %}
{% if forloop.counter|gt:10 %}...{% endif %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4763 次 |
| 最近记录: |