将列表传递到b中的模板

2024-10-01 11:39:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个由post信息组成的list of tuples(list包含tuples) 但我面临的问题是如何传递到瓶子里的模板,我试了很多次,在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

^{pr2}$

当我尝试这个时,我得到了错误500。。。当我检查日志时,原因是:

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


Tags: ofname模板信息id瓶子dbif
1条回答
网友
1楼 · 发布于 2024-10-01 11:39:36

我到处找了找,发现这个作品很好很好。。在

<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>

相关问题 更多 >