1👍
✅
I’m not sure why you would get that result, but this seems like a overly complicated way to do something quite straightforward.
You can use the built in last
filter and with
template tag to access the last item in a list.
{% with article_list|last as last_article %}
<ol class="content" start="{{ last_article.number }}" reversed=true>
{% endwith %}
However, I would recommend you do the ordering and reversing in the view function instead of in the template. Django’s template language is by choice not suited for non trivial logic.
As for the numbering, you can actually explicitly assign a value attribute to a ordered list element. This would solve your problem.
<li value={{ article.number }} ...
Example:
<ol>
<li value=3>it doesn't
<li>have to
<li>make
<li value=42>sense
</ol>
Source:stackexchange.com