在Python Django中如何渲染元组序列详细描述


Python Django中渲染元组序列的实际应用方案一般是通过渲染一个相对数据集,那么一下的文章主要介绍如何在Python Django中渲染模板的方法,希望你会有所收获,以下就是文章的具体介绍。

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

视图层代码:

  1. room = Agente.objects.get(id = t_id)  
  2. all_agent = room.package_dbname  
  3. output = all_agent.split(";")   

编号组成为 agent编号_真名.py

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

模板层代码:

  1. {% for type in output %}  
  2. <tr bgcolor="#EBF2F9" align=center> 
  3. <td align="center"> 
  4. <label>{{type}}</label> 
  5. </td>  

遍历方法其实是与在PY里面写的方法是一样的处理哦!现在有一个问题就是在split的时候会有最后一列为空值。需要过滤处理

解决方法:

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

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



 

评论关闭