In mako, how can I iterate over a list and display each value?

I have a Python list that I put in a template:

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

And I would like to show:

<ul>
<li>Please enter a name</li>
<li>Please enter an email</li>
</ul>
+3
source share
1 answer
<ul>
% for prompt in whateveryoucalledit.values():
  <li>${prompt}</li>
% endfor
</ul>

where whateveryoucalleditis the name under which you decided to pass this container (which, as noted by the remark, is a dict, not a list). In the end, the nice thing about mako is that it is wonderfully close to Python itself (except for the need to “trim” things around the bits and explicitly close blocks, not just indend / deindent ;-).

+3
source

Source: https://habr.com/ru/post/1735141/


All Articles