2013-02-28 85 views
2

我有一个列表包括岗位信息作为元组的名单(名单由元组) ,但我面对的是如何通过它在瓶子模板我已经尝试了很多问题,,并在stackoverflow中检查了大部分问题,我找不到一个好的和明确的问题。通过列表模板瓶

这是我曾尝试:

@route('/v/:name') 
def page_viwer(name): 
    id=db.searchU('user', name) 
    result=db.searchU_forG(id[0][0]) 
    if len(result)>0:#if we got posts 
     return template('v',post=result) 

这里是v.tpl

<html> 
%for post in res: 
    %for id, title, dec, pic,not_needed in post: 
     <h3>{{id}}</h3> 
     <h3>{{title}}</h3> 
     <h3>{{dec}}</h3> 
     <h3>{{pic}}</h3> 
     <br/> 
%end 
</html> 

当我尝试这样做,我得到了错误500 ...当我检查了日志,这是什么原因:

%for id, title, dec, pic in post: TypeError: 'int' object is not iterable

+0

它似乎缺乏'v.tpl'另一个'%end'? – Xiao 2013-11-21 18:17:51

回答

4

我周围挖发现这工作正常和伟大..

<html> 

<table> 
    %for item in res: 
    title:{{item[1]}} 
    <br/> 
    Decription:{{item[2]}} 
    <br/> 
    Picture:{{item[3]}} 
    <br/> 
    posted by:{{item[4]}} 
    <br/> 
    <br/> 
    %end 
</table> 

</html>