Iterate model values in html table

Hi all,
I have a html template with Student table. I want to iterate all Student details in html table with for loop.

This is my HTML file,

 <table>
              <tr style="color: #7abaff">
                  <th>ID</th>
                  <th>Student Name</th>
                  <th>Grade</th>
                  <th>Contact No</th>
                  <th>Address</th>
              </tr>
              {% for i in students %}
              <tr>
                  <td>01</td>
                  <td>{{ i.fname }}</td>
                  <td>12</td>
                  <td>9898989898</td>
                  <td>Ahmedabad</td>
              </tr>
              {% endfor %}
          </table>

and this is my views.py code,

def facultyindex(request):
    students = Student.objects.all()
    return render(request, 'facultyindex.html', {'students':students})

and last below is my Student Model

class Student(models.Model):
    fname = models.CharField(max_length=100)
    lname = models.CharField(max_length=100)
    email = models.CharField(max_length=100)
    password = models.CharField(max_length=100)
    contactno = models.CharField(max_length=100)
    address = models.TextField()
    grade = models.CharField(max_length=100)
    enrollmentstartdate = models.DateField()
    enrollmentenddate = models.DateField()
    daysremaining = models.IntegerField(default=365)
    feespaid = models.DecimalField(max_digits=8, decimal_places=2)
    paymentdate = models.DateField()

    def __str__(self):
        return self.fname + "-" + self.lname

please help

Thanks

Welcome @hardip84 !

It looks like you’re off to a really good start here. What seems to be the issue?

You’re already rendering the fname field, you should be able to add the other fields you need - unless there’s something not working at this point, in which case we’ll need to know what’s going wrong.

Thanks for the reply, i am new to django. I’ve tried all the possible solution but its not working. can u help me further ?

Thanks

Possible solution for what?

You haven’t yet described what the problem or issue is that you’re facing.

What are you seeing that you don’t expect to be seeing? Or, what are you not seeing that you expect to see?

i am not able to get all student list in table using for loop. Whenever i try to run the code. the table values become empty.
what i am doing wrong in this code ? pls help

So you are saying that the table is being rendered, but the <td>{{ i.fname }}</td> is rendering as <td></td>? (Are all the constant values are there and repeated?)

Is that html fragment at the top part of the facultyindex.html template?

How many Student do you have? Are you seeing that many table rows being rendered?

Sorry for the late reply. But it seems like there was some problem with my HTML template. i have used another template and it works fine. Thanks