Articles → DJANGO → Render The Template Conditionally In Django

Render The Template Conditionally In Django






Template




<html>
   <head></head>
   <body>
      {% if age > 18 %}
      <h1>Eligible to vote</h1>
      {% else%}
      <h1>Not eligible to vote</h1>
      {% endif %}
   </body>
</html>





View.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', {'age': 17})



Output




Picture showing the output of rendering the template conditionally 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