1

I am passing this object to my template from my view with the name student_collection

<class 'list'>: [[31, 'John', ‘Jacob', '1'], [31, 'Jeffrey', ‘Mark', '2'], [39, ‘Borris', ‘Hammer', '1']] 

And accessing it as such in my template:

{% for rows in student_collection %} <tr> {% for items in rows %} {% for entry in items %} <td>{{ entry }}</td> {% endfor %} {% endfor %} </tr> {% endfor %} 

I am getting an error at the point {% for entry in items %} django says 'int' object is not iterable why is that I was expecting to iterate through 31,John,Jacob,1 . Any help in this regard would be appreciated.

1 Answer 1

2

I was expecting to iterate through 31,John,Jacob,1

Then you wouldn't need that second inner loop. The first loop gives you each sublist/row in the list of rows, while the inner loop iterates through each row, producing each of the items/entries:

{% for rows in student_collection %} <tr> {% for item in row %} <td>{{ item }}</td> {% endfor %} </tr> {% endfor %} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.