for循环标签

功能:循环标签

对对象(书包)进行循环,可以从小到大,也可以从大到小

没有对象(书包)参数时,会产生一个缺省的循环对象(书包)

能够嵌套循环

  用法:

<for bags=[书包1|书包2|...] [start=起点值] [end=终止值] [step=步长值]>

<被循环的标签>...</被循环的标签>

</for>

·        bags:循环的目标书包,可多值(能同时对多个书包循环),可以从头到尾遍历整个书包内容,缺省书包名为for

·        start:起点值,缺省为0

·        end:终止值,缺省为10

·        step:步长,缺省为1

·        被循环的标签:WebEasy语言标签或html标签,不能为空

chtml>
<for>
	<b>@{for:getSuffix}-</b>
</for>
</chtml>
从0循环到10,最后一位小于10,如图

(例子文件:_samples/for.html)

上实例:一个流量分析的大数据应用例子

列表名

<ul><li style="width:917px;border-top:0px;border-left:0px"><b>实时数据</b></li></ul>
<ul>
	<li style="width:171px;background-color:#008B8B;">时间</li>
	<li style="width:70px;background-color:#008B8B;">访客</li>
	<li style="width:120px;background-color:#008B8B;">ip</li>
	<li style="width:280px;background-color:#008B8B;">来自</li>
	<li style="width:280px;background-color:#008B8B;border-right:1px #B4B4B4 solid;">访问地址</li>
</ul>
查询实时流量记录(vertica数据库)
<esql module=vertica id=list>
select ts,uid,client_ip,case when ref_protocol='' then '' else ref_protocol||'://'||ref_host||ref_uri || (case when ref_para='' then '' else '?' || ref_para end) end as ref,case when page_protocol='' then '' else page_protocol||'://'||page_host||page_uri||(case when page_para='' then '' else '?'||page_para end) end as page from roi.visit_log @{pPage:where} order by ts desc limit 100;
</esql>
for标签循环输出定制列表(注意: bags=list
<for bags=list end="@{list:getLength}">
<ul>
	<li style="width:171px">@{intLeft:@{list:ts}(19)}</li>
	<li style="width:70px">@{list:uid}</li>
	<li style="width:120px">@{list:client_ip}</li>
<if x="@{list:ref}" else=1>
	<li style="width:280px">直接访问</li>
	<li style="width:280px"><a href="@{list:ref}" target=_blank>@{intleft:@{list:ref}(30)}</a> </li>
</if>
	<li style="width:280px;border-right:1px #B4B4B4 solid;"><a href="@{list:page}" target=_blank>@{intleft:@{list:page}(30)}</a> </li>
</ul>
</for>
完整代码
<div id=tab980>
<ul><li style="width:917px;border-top:0px;border-left:0px"><b>实时数据</b></li></ul>
<ul>
	<li style="width:171px;background-color:#008B8B;">时间</li>
	<li style="width:70px;background-color:#008B8B;">访客</li>
	<li style="width:120px;background-color:#008B8B;">ip</li>
	<li style="width:280px;background-color:#008B8B;">来自</li>
	<li style="width:280px;background-color:#008B8B;border-right:1px #B4B4B4 solid;">访问地址</li>
</ul>
<chtml>
<if x="@{pPage:p_host}" else=1>
	<we/>
	<bag id=pPage><we name=where>where page_host='@{pPage:p_host}'</we></bag>
</if>
<esql module=vertica id=list>
select ts,uid,client_ip,case when ref_protocol='' then '' else ref_protocol||'://'||ref_host||ref_uri || (case when ref_para='' then '' else '?' || ref_para end) end as ref,case when page_protocol='' then '' else page_protocol||'://'||page_host||page_uri||(case when page_para='' then '' else '?'||page_para end) end as page from roi.visit_log @{pPage:where} order by ts desc limit 100;
</esql>
<for bags=list end="@{list:getLength}">
<ul>
	<li style="width:171px">@{intLeft:@{list:ts}(19)}</li>
	<li style="width:70px">@{list:uid}</li>
	<li style="width:120px">@{list:client_ip}</li>
<if x="@{list:ref}" else=1>
	<li style="width:280px">直接访问</li>
	<li style="width:280px"><a href="@{list:ref}" target=_blank>@{intleft:@{list:ref}(30)}</a> </li>
</if>
	<li style="width:280px;border-right:1px #B4B4B4 solid;"><a href="@{list:page}" target=_blank>@{intleft:@{list:page}(30)}</a> </li>
</ul>
</for>
</chtml>
<ul>
	<li style="width:171px;background-color:#008B8B;border-bottom:1px #B4B4B4 solid;">时间</li>
	<li style="width:70px;background-color:#008B8B;border-bottom:1px #B4B4B4 solid;">访客</li>
	<li style="width:120px;background-color:#008B8B;border-bottom:1px #B4B4B4 solid;">ip</li>
	<li style="width:280px;background-color:#008B8B;border-bottom:1px #B4B4B4 solid;">来自</li>
	<li style="width:280px;background-color:#008B8B;border-bottom:1px #B4B4B4 solid;border-right:1px #B4B4B4 solid;">访问地址</li>
</ul>
</div>
输出效果

轻开平台资源下载及说明

平台免费下载:http://download.csdn.net/detail/tx18/8381859

最新开发手册下载:http://download.csdn.net/detail/tx18/8411089

开发实例:轻开B2C电子商务网站,免费下载:http://download.csdn.net/detail/tx18/8318585

轻开平台会不定期升级为大家提供更多强大而Easy的功能,请留意最新的开发手册

Django的for循环标签用于在模板中迭代列表、字典和查询集等可迭代对象,并在循环体中输出每个元素的值。 以下是Django中常用的for循环标签: 1. for...in:迭代列表、元组、集合等序列类型。 ```html {% for item in items %} {{ item }} {% endfor %} ``` 2. for...in...empty:迭代列表、元组、集合等序列类型,同时处理空序列的情况。 ```html {% for item in items %} {{ item }} {% empty %} 暂无数据 {% endfor %} ``` 3. for...in...reversed:倒序迭代列表、元组、集合等序列类型。 ```html {% for item in items reversed %} {{ item }} {% endfor %} ``` 4. for...in...if:迭代列表、元组、集合等序列类型,并根据条件过滤元素。 ```html {% for item in items %} {% if item > 5 %} {{ item }} {% endif %} {% endfor %} ``` 5. for...in...if...else:迭代列表、元组、集合等序列类型,并根据条件过滤元素,同时处理条件不成立的情况。 ```html {% for item in items %} {% if item > 5 %} {{ item }} {% else %} 不符合条件 {% endif %} {% endfor %} ``` 6. for...in...else:迭代列表、元组、集合等序列类型,同时处理空序列和非空序列的情况。 ```html {% for item in items %} {{ item }} {% empty %} 暂无数据 {% endfor %} ``` 7. for...in...counter:迭代列表、元组、集合等序列类型,并输出当前迭代的次数。 ```html {% for item in items %} {{ forloop.counter }}. {{ item }} {% endfor %} ``` 8. for...in...counter0:迭代列表、元组、集合等序列类型,并输出当前迭代的次数(从0开始)。 ```html {% for item in items %} {{ forloop.counter0 }}. {{ item }} {% endfor %} ``` 9. for...in...cycle:迭代列表、元组、集合等序列类型,并轮流输出指定的多个值。 ```html {% for item in items %} {{ item }}{% cycle 'red' 'green' 'blue' %} {% endfor %} ``` 以上为Django中常用的for循环标签,可以根据实际需求选择使用。
评论 31
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值