Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26317825
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: Python/Ruby

2010-03-15 11:07:59

解决Django渲染元组序列

[整理时间:2010-3-15]

一般渲染模板的方法是渲染一个数据集。现在需要渲染出来一个字段通过分割之后输出的内容。

视图层代码:

room       = Agente.objects.get(id = t_id)

all_agent = room.package_dbname

output = all_agent.split(";")     #编号组成为   agent编号_真名.py

return render_to_response('moni/tagent.html',{'s_h':room,'output':output})

模板层代码:

{% for type in output %}

<tr bgcolor="#EBF2F9" align=center>

  <td align="center">

  <label>{{type}}label>

td>

遍历方法其实是与在PY里面写的方法是一样的处理哦!

现在有一个问题就是在split的时候会有最后一列为空值。需要过滤处理

解决方法:

result  = output[0:len(output)-1]

这样就可以分割得到想要的遍历的数据集出来!

阅读(624) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-05-10 12:44:14

正确的做法: {% for type in output %} {%for ele in type%} {{ele}} {%endfor%} {%endfor%}

hkebao2010-05-10 11:38:23

看一下序列里面套序列如何在模板里面解析 {% for type in output %} {%for a in type%} {{a.0}} {%endfor%} {%endfor%}