[英]In mako, how can I cycle through a list and display each value?
I have a Python list that I'm supplying to the template: 我有一个Python列表,我正在提供给模板:
{'error_name':'Please enter a name',
'error_email':'Please enter an email'}
And would like to display: 并希望显示:
<ul>
<li>Please enter a name</li>
<li>Please enter an email</li>
</ul>
<ul>
% for prompt in whateveryoucalledit.values():
<li>${prompt}</li>
% endfor
</ul>
where whateveryoucalledit
it is the name under which you chose to pass that container (which, as a comment noticed, is a dict, not a list). 其中
whateveryoucalledit
它是根据你选择了传球该容器(其中,作为评论注意到,是一个字典,而不是一个列表)的名称。 The nice thing about mako, after all, is precisely that it's wonderfully close to Python itself (except for the need to "strop" things around a bit, and explicitly close blocks rather than just indend/deindent;-). 毕竟,关于mako的好处恰恰在于它非常接近Python本身(除了需要“稍微绕过”一些东西,并明确地关闭块而不仅仅是indend / deindent ;-)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.