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
Click to Enlarge