variables - Django Templates Last Updated : 14 May, 2025 Comments Improve Suggest changes Like Article Like Report Prerequisite- Django TemplatesIn Django, templates are used to dynamically generate HTML content by combining static HTML with dynamic data from views. One of the simplest and most useful features of Django templates is the use of variables. Variables allow you to display data passed from a view inside your HTML.Syntax{{ variable_name }}Example: Suppose we pass a context with the following data{ 'first_name': 'Naveen', 'last_name': 'Arora'}And in your template:My first name is {{ first_name }}. My last name is {{ last_name }}.Output:My first name is Naveen. My last name is Arora.This is how Django lets you inject dynamic content directly into your HTML templates using the Django Template Language (DTL).Implementation Example1. Create a Django Project and AppIf the project and app is alreday created, proceed to further steps and if not then refer to the following article to learn hoe to create and setup:Refer to the following articles to check how to create a project and an app in Django. How to Create a Basic Project using MVT in Django?How to Create an App in Django ?Assume your project is named geeksforgeeks and your app is named geeks.2. Create a View with Context DataAdd this code in geeks/views.py: Python from django.shortcuts import render def geeks_view(request): context = { "first_name": "Prajjwal", "last_name": "Vishwkarma", } return render(request, "geeks.html", context) 3. Configure URL RoutingIn geeks/urls.py add the following code to link the view: Python from django.urls import path from . import views urlpatterns = [ path('',views.geeks_view, name = 'geeks_view'), ] 4. Create the TemplateCreate a file named geeks.html inside a templates folder of the app, if there isn't a templates folder then create one and then create the required html files in it (all the html files will be served to the app from this folder). html My First Name is {{ first_name }}. <br/> My Last Name is {{ last_name }}. To check if the app is working, run the app using command- python manage.py runserver and visit the development URL - http://127.0.0.1:8000/ Snapshot of the development server Comment More infoAdvertise with us Next Article Django Template Tags N NaveenArora Follow Improve Article Tags : Python Python Django Django-templates Practice Tags : python Similar Reads Django Templates Templates are the third and most important part of Django's MVT Structure. A Django template is basically an HTML file that can also include CSS and JavaScript. The Django framework uses these templates to dynamically generate web pages that users interact with. Since Django primarily handles the ba 7 min read variables - Django Templates Prerequisite- Django TemplatesIn Django, templates are used to dynamically generate HTML content by combining static HTML with dynamic data from views. One of the simplest and most useful features of Django templates is the use of variables. Variables allow you to display data passed from a view ins 2 min read Django Template Tags Prerequisite: What are Django Templates?Django provides a powerful templating engine that allows us to add logic directly into our templates using template tags. These tags enable everything from control structures (like if and for loops), to inserting dynamic content, to template inheritance. Templ 4 min read extends - Django Template Tags Djangoâs {% extends %} tag allows you to reuse a base template across multiple pages, so you donât have to repeat the same HTML code in every template. This makes your templates cleaner, easier to maintain, and helps keep a consistent layout throughout your site.Syntax: {% extends 'base_template.htm 2 min read if - Django Template Tags The {% if %} tag in Django templates allows us to control what content is displayed based on certain conditions. We can use it to show or hide parts of a page depending on whether a condition is met.Syntax of the {% if %} Tag{% if variable %}// statements{% else %}// statements{% endif %}condition: 3 min read for loop - Django Template Tags Django templates allow you to render dynamic data by embedding Python-like logic into HTML. The for loop is one of the most commonly used template tags, enabling you to iterate over lists or other iterable objects. It helps you display repeated content (like lists, tables, etc.) in your templates wi 3 min read comment - Django template tags A Django template is a text document or a Python string marked-up using the Django template language. Django being a powerful Batteries included framework provides convenience to rendering data in a template. Django templates not only allow passing data from view to the template but also provide som 2 min read include - Django Template Tags A Django template is a text document or a Python string marked-up using the Django template language. Django being a powerful Batteries included framework provides convenience to rendering data in a template. Django templates not only allow passing data from view to template, but also provides some 2 min read url - Django Template Tag A Django template is a text document or a Python string marked-up using the Django template language. Django being a powerful Batteries included framework provides convenience to rendering data in a template. Django templates not only allow passing data from view to template, but also provides some 3 min read cycle - Django Template Tags A Django template is a text document or a Python string marked-up using the Django template language. Django being a powerful Batteries included framework provides convenience to rendering data in a template. Django templates not only allow passing data from view to template, but also provides some 3 min read Like