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

ens*_*are 4 python pylons templates mako

我有一个向模板提供的 Python 列表:

{'error_name':'Please enter a name',
 'error_email':'Please enter an email'}
Run Code Online (Sandbox Code Playgroud)

并想显示:

<ul>
<li>Please enter a name</li>
<li>Please enter an email</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

Ale*_*lli 5

<ul>
% for prompt in whateveryoucalledit.values():
  <li>${prompt}</li>
% endfor
</ul>
Run Code Online (Sandbox Code Playgroud)

其中whateveryoucalledit它是您选择传递该容器的名称(正如评论所注意到的那样,它是一个字典,而不是一个列表)。毕竟,mako 的好处恰恰在于它非常接近 Python 本身(除了需要稍微“删除”一些东西,并显式关闭块而不仅仅是 indend/deindent;-)。