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