Devnote

Web Development Blog Company, Services India

MySQL Error 121 Duplicate key on write - Practical Repair Strategy
MySQL Error 121 Duplicate key on write – Practical Repair Strategy
February 13, 2026
PHP cURL error 60: SSL certificate problem - Windows & Linux Fix
PHP cURL error 60: SSL certificate problem – Windows & Linux Fix
February 11, 2026
Fix localhost refused to connect After Installing XAMPP / WAMP
Fix “localhost refused to connect” After Installing XAMPP / WAMP
February 9, 2026
Composer Error Memory exhausted When Installing Packages - Real Fix
Composer Error: Memory exhausted When Installing Packages – Real Fix
February 6, 2026
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci - Safe Migration Guide
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci – Safe Migration Guide
February 4, 2026
Devnote

Type and hit Enter to search

  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Devnote
  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Django - Template System Language With Example

Django – Template System Language With Example

Image
Devnote team
March 2, 2020
3
921 Views
0 Comments

So here is the full documentation of Django template system

Render Function

This function takes three parameters :

Request – The initial request.
Template – The path relative to the TEMPLATE_DIRS option in the project settings.py variables.
Parameters – A dictionary that contains all variables needed in the template.

Syntax:

return render(Request, Template, Parameters)

Django Template Language (DTL)

  1. Display Variables

The variable by the variable sent by the view in the third parameter of the render function.{{variable}}

#index.html
<!DOCTYPE html>
<html>
<head>
	<title>Displaying Variables</title>
</head>
<body>
	<span>Today is {{Date}}</span>
</body>
</html>
#views.py
import datetime

def index(request):
    Date = datetime.datetime.now().date()
    return  render(request, "index.html", {"Date" : Date})

Output :

Today is March 2, 2020, 11:50 a.m.

2. Filters

Filters structure looks like the following : {{variable|filters}}.

{{string|truncatewords:40}} – This filter will truncate the string.
{{string|lower}} – Converts the string to lowercase.
{{string|upper}} – Converts the string to uppercase.
{{string|escape|linebreaks}} – Escapes string contents, converts line breaks to tags.

Example :

#index.html
<!DOCTYPE html>
<html>
<head>
	<title>Displaying Variables</title>
</head>
<body>
	<p>{{ paragraph|truncatewords:40 }}</p><br>
	<p>{{ paragraph|upper }}</p><br>
	<p>{{paragraph|escape|linebreaks}}</p>
</body>
</html>
#views.py
def index(request):

    paragraph = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodoconsequat. Duis aute irure dolor in reprehenderit in voluptate velit essecillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat nonproident, sunt in culpa qui officia deserunt mollit anim id est laborum."

    return  render(request, "index.html", {"paragraph" : paragraph})

Django Template System Output :

truncatewords

lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodoconsequat. duis aute irure dolor in reprehenderit in ...

upper

LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISICING ELIT, SED DO EIUSMODTEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA ALIQUA. UT ENIM AD MINIM VENIAM,QUIS NOSTRUD EXERCITATION ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODOCONSEQUAT. DUIS AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSECILLUM DOLORE EU FUGIAT NULLA PARIATUR. EXCEPTEUR SINT OCCAECAT CUPIDATAT NONPROIDENT, SUNT IN CULPA QUI OFFICIA DESERUNT MOLLIT ANIM ID EST LABORUM.

escape | linebreaks

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodoconsequat. Duis aute irure dolor in reprehenderit in voluptate velit essecillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat nonproident, sunt in culpa qui officia deserunt mollit anim id est laborum.

3. Tags

Tags is following operations: if condition, for loop, template inheritance and more…

Tag if

#index.html
<!DOCTYPE html>
<html>
<head>
	<title>Tags if condition</title>
</head>
<body>
	<p>Today is : {{ Date }}</p>
	{% if Date.day == 1 %}
	
	Today is Month first day.

	{% elif Date.day == 2 %}

	Today is Month second day.

	{% else %}

	Don't know

	{% endif %}

</body>
</html>
#views.py
def index(request):

	Date = datetime.datetime.now().date()
    return  render(request, "index.html", {"Date" : Date})

Output :

Today is Month second day.

Tag for

#index.html
<!DOCTYPE html>
<html>
<head>
	<title>Tags if condition</title>
</head>
<body>
	<p>
    {% for daynames in weekName  %}
    {{ daynames }}
    </p>
    {% endfor %}
</body>
</html>
#views.py
def index(request):

	Date = datetime.datetime.now().date()
	weekName = ['Monday', 'Tueday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
    return  render(request, "index.html", {"Date" : Date , "weekName" : weekName})

Output :

Monday
Tueday
Wednesday
Thursday
Friday
Saturday
Sunday

Categories:

djangopython

Other Articles

template does not exits
Previous

Django TemplateDoesNotExist Error on Windows machine

Paytm Payment Gateway
Next

Paytm Payment Gateway Integration in PHP

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

How to Set Up Google Authentication with Django

How to Set Up Google Authentication with Django

February 17, 2021
How to make a field read-only in Django admin

How to make a field read-only in Django admin?

February 9, 2021
How to disable admin pagination in Django?

How to disable admin pagination in Django?

February 5, 2021
How to show the larger number on the listview page?

How to show the larger number on the listview page?

February 4, 2021
Devnote

Devnote provides a collection of tutorials about PHP, Laravel, WordPress, Django, MySQL, Bootstrap, Jquery, Ajax, APIs, CRUD operations, etc.

Devnote © , All Rights Reserved.

Page Links

  • Home
  • About us
  • Blog
  • Contact US
  • Site map

Category

  • PHP
  • Laravel
  • wordpress
  • HTML
  • jQuery

Follow Us

Facebook Instagram Twitter Youtube Linkedin Pinterest
Morbi, Gujarat, India - 363641
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT
Advertisement