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

发布于 2024-08-23 04:30:07 字数 280 浏览 2 评论 0原文

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

{'error_name':'Please enter a name',
 'error_email':'Please enter an email'}

并且想要显示:

<ul>
<li>Please enter a name</li>
<li>Please enter an email</li>
</ul>

I have a Python list that I'm supplying to the template:

{'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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜清冷一曲。 2024-08-30 04:30:07
<ul>
% for prompt in whateveryoucalledit.values():
  <li>${prompt}</li>
% endfor
</ul>

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

<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). 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;-).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文