Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an ordered list out of a python list item

Have a list called whatever that I want to itemize in Jinja:

<ol>
{% for item in whatever %}
<tr>
    <td>
       <li> {{ item }}</li>
    </td>
</tr>
{% endfor %}
</ol>

However, when I implement this in this way, I get unordered list output rather than sequential numbers, i.e.

  • item 1
  • item 2
  • etc.

rather than

  1. item 1
  2. item 2
  3. etc.
like image 631
fox Avatar asked Dec 06 '25 06:12

fox


1 Answers

It is actually a problem with your html (and not python / jinja). It you remove the tr/td tags it will be ok.

Update: If you insist on using the table tags, drop the ol/li tags, and use the loop object that is implicitly defined in the jinja for loop. That is,

<td>{{loop.index}}. {{item}}</td>

will give you enumerated item.

like image 94
vonPetrushev Avatar answered Dec 08 '25 19:12

vonPetrushev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!