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