计数烧瓶模板中的行数 [英] count number of rows in flask templates
问题描述
我从视图发送一个变量到由数据库中的数据组成的模板
这就是我在我的模板中使用的内容
{%for i in data%}
< tr>
< td> {{i.id}}< / td>
< td> {{i.first_name}}< / td>
< td> {{i.last_name}}< / td>
< td> {{i.email}}< / td>
< / tr>
{%endfor%}
这个循环中有七个条目,我需要显示计数租约建议如何做到这一点
在循环内部,您可以访问一个名为 loop的特殊变量
,您可以看到 {{loop.length}}
这是你可以用循环辅助变量完成的工作: loop.index 当前迭代的循环。 (1索引) loop.index0 循环的当前迭代。 (0索引) loop.revindex 从循环结尾开始的迭代次数(1索引) loop.revindex0 从循环结尾开始的迭代次数(0为索引) loop.first 如果是第一次迭代,则为true。
loop.length $ b
loop.cycle 在序列列表之间循环的辅助函数。请参阅下面的说明。
loop.depth 指示呈现当前所处的递归循环深度。从级别1开始
loop.depth0 指示当前呈现在递归循环中的深度。从0级开始
编辑:
要查看de for循环之外的项目的数量,您可以从您的视图中生成另一个变量,如 count_data = len(data)
,或者您可以使用<$
长度
过滤器: $数据计数是{{数据|长度}}:
{数据%中的i%}
< tr>
< td> {{i.id}}< / td>
< td> {{i.first_name}}< / td>
< td> {{i.last_name}}< / td>
< td> {{i.email}}< / td>
< / tr>
{%endfor%}
i have send a variable from my views to templates which consist of the data from database
this is what i am using in my template
{% for i in data %}
<tr>
<td>{{i.id}}</td>
<td>{{i.first_name}}</td>
<td>{{i.last_name}}</td>
<td>{{i.email}}</td>
</tr>
{% endfor %}
there are seven entries in this loop , i need to show count lease suggest how can i do this
Inside the loop you can access a special variable called loop
and you can see the number of items with {{ loop.length }}
This is all you can do with loop auxiliary variable:
loop.index The current iteration of the loop. (1 indexed)
loop.index0 The current iteration of the loop. (0 indexed)
loop.revindex The number of iterations from the end of the loop (1 indexed)
loop.revindex0 The number of iterations from the end of the loop (0 indexed)
loop.first True if first iteration.
loop.last True if last iteration.
loop.length The number of items in the sequence.
loop.cycle A helper function to cycle between a list of sequences. See the explanation below.
loop.depth Indicates how deep in deep in a recursive loop the rendering currently is. Starts at level 1
loop.depth0 Indicates how deep in deep in a recursive loop the rendering currently is. Starts at level 0
EDIT:
To see the count of items outside de for loop you can generate another variable from your view like count_data = len(data)
or you can use the length
filter:
Data count is {{ data|length }}:
{% for i in data %}
<tr>
<td>{{i.id}}</td>
<td>{{i.first_name}}</td>
<td>{{i.last_name}}</td>
<td>{{i.email}}</td>
</tr>
{% endfor %}
这篇关于计数烧瓶模板中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!