Articles → DJANGO → Context In Templates In Django

Context In Templates In Django






Context In Templates





Example




  1. Create a template with template variable.
  2. Pass context in function-based view.

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




Picture showing the output of the context in templates in Django
Click to Enlarge


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

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250