使用 floor 循环遍历列表 jinja django python
iterating through list with floor loop jinja django python
我有这个数组:
分数 = [45.62, 51.87, 33.12, 39.37, 33.12]
我想遍历列表,并将每个项目传递给 html 模板。
使用 jinga,我尝试了以下方法:
{% for items in scores %}
{{ items }}
<br>
{% endfor %}
我希望上面的代码能像这样打印出列表中的每一项:
45.62
51.87
33.12
等...
但它没有,它只是将整个列表作为一个列表打印在一行上。
我也试过这个:
{% for items in scores %}
{{ scores.0 }}
<br>
{% endfor %}
这只打印出列表的第一个分数,而不是其他分数。我想单独打印出每个乐谱。请帮忙!我正在使用 Django 1.9。我知道这是 jinja,不确定是不是 jinja2?
尝试更改变量名称。也许您在上下文中有另一个名为 items
的变量。在循环中使用非复数的变量名会更有意义。
{% for score in scores %}
{{ score }}
<br>
{% endfor %}
感觉列表和你输入的不一样 question.Try 这个
{% for items in scores.0 %}
{{ items }}
<br>
{% endfor %}
我有这个数组: 分数 = [45.62, 51.87, 33.12, 39.37, 33.12]
我想遍历列表,并将每个项目传递给 html 模板。
使用 jinga,我尝试了以下方法:
{% for items in scores %}
{{ items }}
<br>
{% endfor %}
我希望上面的代码能像这样打印出列表中的每一项:
45.62
51.87
33.12
等...
但它没有,它只是将整个列表作为一个列表打印在一行上。
我也试过这个:
{% for items in scores %}
{{ scores.0 }}
<br>
{% endfor %}
这只打印出列表的第一个分数,而不是其他分数。我想单独打印出每个乐谱。请帮忙!我正在使用 Django 1.9。我知道这是 jinja,不确定是不是 jinja2?
尝试更改变量名称。也许您在上下文中有另一个名为 items
的变量。在循环中使用非复数的变量名会更有意义。
{% for score in scores %}
{{ score }}
<br>
{% endfor %}
感觉列表和你输入的不一样 question.Try 这个
{% for items in scores.0 %}
{{ items }}
<br>
{% endfor %}