Reputation: 3503
I have some problem with bottle template. I can not pass python list to template. My code is below:
@route('/'):
def home():
return template('home', var=['item1', 'item2'])
And this is home.tpl:
<html>
<ul>
#for item in var:
<li>{{item}}</li>
#end
</ul>
</html>
I think it work but exception not defined variable 'item' throwed. Could please tell me where my error?
Upvotes: 1
Views: 881
Reputation: 11
If you want to iterate through the list in the reverse order, the following template will work.
<html>
<ul>
%for i in range(len(var)-1,-1,-1):
<li>{{var[i]}}</li>
%end
</ul>
</html>
Upvotes: 1
Reputation: 1121744
The bottle template syntax uses %
, not #
to mark python(ish) blocks:
<html>
<ul>
%for item in var:
<li>{{item}}</li>
%end
</ul>
</html>
Upvotes: 3