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

4

1 回答 1

5

我已经四处挖掘,发现这很好用而且很棒..

<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>
于 2013-02-28T09:59:42.380 回答