Ham*_*daq 2 python template-engine wsgi list bottle
我有一个列表,其中包含作为元组列表的帖子信息(列表由元组组成),但我面临着如何将其传递给瓶子中的模板的问题,我已经尝试了很多,并检查了 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)
Run Code Online (Sandbox Code Playgroud)
这是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>
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,我收到错误 500 ...当我检查日志时,原因是:
%for id, title, dec, pic in post:
TypeError: 'int' object is not iterable
我四处挖掘,发现这工作得很好而且很棒..
<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>
Run Code Online (Sandbox Code Playgroud)