The for loop works, but instead of adding the data to the table, it adds the data beneath the existing table.
laptop_list.html
<div class="container">
<div class="table-responsive-sm">
<table class="table">
{%for laptop in laptops%}
<div class="table-responsive-sm">
<tbody>
<tr>
<td>{{laptop.laptop_id}}</td>
<td>{{laptop.make}}</td>
<td>{{laptop.model}}</td>
<td>{{laptop.specification}}</td>
<td>{{laptop.warranty}}</td>
<td>{{laptop.condition}}</td>
<td>{{laptop.price}}</td>
</tr>
</tbody>
</div>
</table>
{%endfor%}
</div>
</div>
models.py
class Laptop(models.Model):
make = models.CharField(max_length = 100)
model = models.CharField(max_length = 100)
specification = models.CharField(max_length = 100)
warranty = models.CharField(max_length = 100)
condition = models.CharField(max_length = 100)
price = models.CharField(max_length = 100)
added_by = models.ForeignKey(User, default = None, on_delete=models.CASCADE)
views.py
def laptop_list(request):
laptops = Laptop.objects.all()
return render(request,'laptops/laptop_list.html',{'laptops':laptops})