5👍
I think you are trying to print index of every row in the table. For that you have to iterate over a list of indices. Create this list in your django view
list = []
for i in range(0,list_length):
list.append(i)
Then pass this list in your django template and iterate over it
{% for i in list %}
<tr>
<td>{{ i }}</td>
</tr>
{% endfor %}
This should work for you.
0👍
A list itself may be iterable, but a single integer on its own is not a list.
If you want to iterate from zero up to an integer, you can use something like Python’s range(n)
to create an iterator for those values. That’s for naked Python, Django appears to require a slightly more complex method, as per Numeric for loop in Django templates.
Otherwise, you possibly need to iterate over the list itself rather than its length (depending on what you’re trying to do and whether you need a list ‘index’ within the loop).
- [Django]-Is this a good way to demonstrate Nodejs (expressjs) advantage over Rails/Django/etc?
- [Django]-Django DB Design – Maintaining common and historical data
- [Django]-Define component schema with drf-spectacular for django API
- [Django]-Cannot access admin panel after setting up django-oauth-toolkit
- [Django]-How to associate invited users with the inviter's Company/group?