fox
fox

Reputation: 16506

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.

rather than

  1. item 1
  2. item 2
  3. etc.

Upvotes: 3

Views: 1976

Answers (1)

vonPetrushev
vonPetrushev

Reputation: 5599

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.

Upvotes: 4

Related Questions