Articles → DJANGO → Context in templates in Django

Context in templates in Django






Context in templates





Example









Create a template with template variable




<html>
	<head></head>
	<body>
		<h1>This is the first heading</h1>
		<h2>This is the second heading</h2>
		<h3>{{Name}}
	</body>
</html>





Pass context in function-based view




def home(request):
  return render(request, "FirstTemplate.html", {
    "Name": "Karan"
  })



Output





Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, June 11, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250