Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有很多图标,名称为 icon1、icon2、icon3 等等......它们来自服务器
如何制作forloop并NUMBER自动在循环中设置该图标?
NUMBER
我试过这个:
{% for i in "1234" %} {{icon}}{{forloop.counter}} {% endfor %}
但这并没有给我想要的东西。为什么我不能这样做:
{{ icon{{forloop.counter}} }},
但这给了我错误,说它无法解析表达式
我猜你正在寻找你的icon变量和循环计数器的串联。
icon
{% for i in "1234" %} {% with c=forloop.counter|stringformat:"s" %} {{icon|add:c}} {% endwith %} {% endfor %}