在 mako 中,如何循环浏览列表并显示每个值?
我有一个向模板提供的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其中
whateveryoucalledit
它是您选择传递该容器的名称(正如评论所注意到的那样,它是一个字典,而不是一个列表)。毕竟,mako 的好处恰恰在于它与 Python 本身非常接近(除了需要稍微“删除”一些东西,并显式关闭块而不仅仅是 indend/deindent;-)。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;-).