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


Picture showing the output of the Dynamically render template using loop in Django

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, June 14, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250