简体   繁体   English

在mako中,如何循环显示列表并显示每个值?

[英]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.

相关问题 每次循环时,如何才能显示列表的下一项 - Each time I go through a loop, how can I get the next item of a list to display 如何循环浏览 flask 中的会话? - How can I cycle through sessions in flask? 如何循环浏览图像中的单个像素并输出每行的最高RGB值像素? - How can I cycle through individual pixels in an image and output the highest RGB valued pixel of each row? 如何循环遍历列表并为每个不同的值启动另一个循环? - How can I loop through a list and for each distinct value initiate another loop? 在python pygame中使用类更改对象颜色时,如何在列表项中“循环”? - How can I 'cycle' through list items when using classes in python pygame to change object colors? Python Mako模板 - 如何基于上下文中的值动态决定调用哪个def或函数? - Python Mako templating - How can I dynamically decide which def or function to call based on a value in the context? 如何在 Django Mako 模板中显示 ${&#39;None&#39;}? - How do I display ${'None'} in a Django Mako template? 如何遍历文件列表并打开每个文件 - How can I iterate through a list of files and open each file 如何遍历图像列表并在 Tkinter 中显示它们 - How can I Iterate through a list of Images and Display them in Tkinter 如何通过导入的CSV文件循环每个值? - How Can I Loop Each Value through an Imported CSV File?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM