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