Title: Enumerate element with tag ol in for loop
Tags: django
Question: I'd like to enumerate the elements in for loop with tag 'ol' with code:
{% for topic in topics  %}
<ol&gt;
<li&gt;{{ topic }}</li&gt;
</ul&gt;
{% endfor %}
It displays
1.Python
1.Javascript
1.SQL
When tried:
{% for topic in topics  %}
<ol&gt;
<li&gt;{{ forloop.counter }}{{ topic }}</li&gt;
</ol&gt;
{% endfor %}
It outputs:
1.1.Python
1.2.Javascript
1.3.SQL
Refactor the code as and works:
{% for topic in topics  %}
<ul&gt;
<li&gt;{{ forloop.counter }}. {{ topic }}</li&gt;
</ul&gt;
{% endfor %}
The solution seem cumbersome, Could it be achieve in a straight-forwards way?

Here is the accepted answer: You need just move <ol&gt; tag declaration outside forloop,
to prevent new list creation on each iteration:
<ol&gt;
{% for topic in topics  %}
<li&gt;{{ topic }}</li&gt;
{% endfor %}
</ol&gt;
Note: Remove {{forloop.counter}}


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:05/16/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<django>', 'Title': 'Enumerate element with tag ol in for loop', 'ViewCount': 102, 'id': 50361510, 'user_AboutMe': '', 'user_AccountId': 9857812.0, 'user_DisplayName': 'AbstProcDo', 'user_Reputation': 18429.0, 'user_Views': 1382.0, 'user_id': 7301792.0}}