Articles → DJANGO → Dynamically render template using loop in Django
Dynamically render template using loop in Django
Template
<html>
<head>
</head>
<body>
<table border="1">
{% for student in EligibleStudents %}
<tr>
<td>
{{ student }}
</td>
<td>
Eligible
</td>
</tr>
{% endfor %}
</table>
</body>
</html>
Change in views.py in TestModule
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def home(request):
return render(request, "FirstTemplate.html",{"EligibleStudents":['Student1','Student2','Student3']})
Output
Click to Enlarge