Nip*_*ips 2 django django-templates
我在模板中循环:
{% for item in items %}
<div class="item">
{{ forloop.counter }}) {{ item.name }}
</div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我想将forloop.counter显示为字母(a,b,c,d,e ...),但不使用ul-> li标签,仅使用forloop.counter.怎么做?
thi*_*nom 10
您可以制作自定义过滤器:
@register.filter
def to_char(value):
return chr(98-value)
Run Code Online (Sandbox Code Playgroud)
然后在你的模板中:
{{forloop.counter|to_char}}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
638 次 |
| 最近记录: |