0
I have a loop 'for" in the template only I want it to show a certain amount result.
{% for form in form %}
<tr>
<td><img src="../static/img/arrow-gray.png" alt="">
<font color="#e3068f"> IGLO{{ form.callsign }}</font></td>
<td>{{ form.username }} <b>{{ form.sobrename }}</b></td>
<td>{{ form.last_seen }}</td>
</tr>
{% endfor %}
if I use {{ for form in form }} it shows the result
Now if I put "{{ for form in range(2) }}" I only want to show 2 result, it shows nothing.
Thanks worked... You can help me I have a database with several names, I wanted you to show me only the last 5 records so I did {% for i in range(5, 0, -1) %} just so show me the last 5, wanted you to show me the last one you logged into the database
– Dalmo Cabral
Opa @Dalmocabral if it worked can mark the answer as accepted? About this problem, you have to change the query. If your table is indexed, you can sort the elements (
ORDER BY
) by the decreasing index or if you have any insertion date may be as well. This treatment should be done primarily in the query pq it is very heavy to treat later on the front.– Igor Cavalcanti