SlideShare a Scribd company logo
5
Most read
6
Most read
10
Most read
Django Web Framework
TEMPLATE
TEMPLATE
 A template in Django is basically written in HTML in a .html file.
 Django framework efficiently handles and generates dynamic HTML web
pages that are visible to the end-user.
 Django mainly functions with a backend so, in order to provide a
frontend and provide a layout to our website, we use templates.
TEMPLATE
 In current project, we will create a single template directory/folder that
will contain all html files and that can be spread over the entire project
for simplicity.
 Create a folder/directory in command prompt on your project path using
DOS (Disk Operating System) command md (make directory)
 Example :
(djangowork) C:UsersLenovoweekdays_django_batchtemplate_inheritance>md template
Project path
TEMPLATE
 Add template in settings.py file,Write following commands,line no.14 and
17
Variable_
name
folder_name
Add varaiable name here
DJANGO TEMPLATE LANGUAGE
 A Django template is a text document or a Python string marked-up using the Django
template language.
 Some constructs are recognized and interpreted by the template engine.
 A template contains variables, which get replaced with values when the template is
evaluated, and tags, which control the logic of the template.
 A template is rendered with a context. Rendering replaces variables with their values, which
are looked up in the context, and executes tags. Everything else is output as is.
DJANGO TEMPLATE LANGUAGE
 The syntax of the Django template language involves four constructs.
1. Variable
 A variable outputs a value from the context, which is a dict-like object mapping keys to
values.
 Variables are surrounded by {{ }} like this .
 Use a dot (.) to access attributes of a variable.
 In html file, we write :
<h1>My name is {{firstname}} {{lastname}}</h1>
In views .py file create context variable as a dictionary.
With context {‘firstname’:’Deepali’ ‘lastname’:’Shinkar’} this template renders to :
<h1>My name is Deepali Shinkar</h1>
Use a dot (.) to access attributes of a variable.
DJANGO TEMPLATE LANGUAGE
2. Filter
When we need to modify variable before displaying ,we can use filter pipe ‘|’ is used
to apply filter.
Syntax : {{variable | filter}}
Example :{{firstname | upper}}
Some of filters take argument :
Syntax : {{variable | filter : argument}}
DJANGO TEMPLATE LANGUAGE
 Float Format :When used without argument rounds a floating point number
to one decimal place but only if there is a decimal part to be displayed.
 Example :
 56.24321 ---{{value | floatformat}} -56.2
 56.00 ---{{value | floatformat}} -56
 56.3700 ---{{value | floatformat}} -56.4
 56.24321 ---{{value | floatformat:2}} -56.24
DJANGO TEMPLATE LANGUAGE
 3.Tags
 Tags provide arbitrary logic in the rendering process.
 Tags are surrounded by {%%} like this.
Examples :
 Some tags require beginning and ending tags.
{% csrf_token %}
{% url ‘add’ %}
{% includes ‘base.html’ %}
etc.
DJANGO TEMPLATE LANGUAGE
 Some tags require beginning and ending tags. Like this
 If tag : It executes a variable and if that variable is true then execute html
tag inside a if body.
Syntax :
 For tag : Evaluate a for loop any number of times which is depend on iterable
object.
Syntax :
{% if variable or condition %}
Html tags
{% endif %}
{% for variable in iterable_object
%}
{{variable}}
{% endfor %}

More Related Content

Similar to steps for template in django for project (20)

PPTX
Web development with django - Basics Presentation
Shrinath Shenoy
 
PPTX
The Django Web Application Framework 2
fishwarter
 
PPTX
The Django Web Application Framework 2
fishwarter
 
PPT
Django for n00bs
Jen Zajac
 
PDF
بررسی چارچوب جنگو
railsbootcamp
 
PDF
Web development django.pdf
KomalSaini178773
 
PPTX
Introduction to django
Vlad Voskoboynik
 
PPTX
Tango with django
Rajan Kumar Upadhyay
 
PPTX
Tango with django
Jaysinh Shukla
 
PPTX
Django crush course
Mohammed El Rafie Tarabay
 
PDF
Django tutorial
Ksd Che
 
PPTX
Introduction to Django
Ahmed Salama
 
PPTX
Basic Python Django
Kaleem Ullah Mangrio
 
PDF
Django 1.10.3 Getting started
MoniaJ
 
PPTX
Learning Web Development with Django - Templates
Hsuan-Wen Liu
 
KEY
Introduction Django
Wade Austin
 
PPTX
Django Girls Tutorial
Kishimi Ibrahim Ishaq
 
PDF
Rapid web application development using django - Part (1)
Nishant Soni
 
PPTX
Django - Python MVC Framework
Bala Kumar
 
PDF
Introduction to Python and Django
solutionstreet
 
Web development with django - Basics Presentation
Shrinath Shenoy
 
The Django Web Application Framework 2
fishwarter
 
The Django Web Application Framework 2
fishwarter
 
Django for n00bs
Jen Zajac
 
بررسی چارچوب جنگو
railsbootcamp
 
Web development django.pdf
KomalSaini178773
 
Introduction to django
Vlad Voskoboynik
 
Tango with django
Rajan Kumar Upadhyay
 
Tango with django
Jaysinh Shukla
 
Django crush course
Mohammed El Rafie Tarabay
 
Django tutorial
Ksd Che
 
Introduction to Django
Ahmed Salama
 
Basic Python Django
Kaleem Ullah Mangrio
 
Django 1.10.3 Getting started
MoniaJ
 
Learning Web Development with Django - Templates
Hsuan-Wen Liu
 
Introduction Django
Wade Austin
 
Django Girls Tutorial
Kishimi Ibrahim Ishaq
 
Rapid web application development using django - Part (1)
Nishant Soni
 
Django - Python MVC Framework
Bala Kumar
 
Introduction to Python and Django
solutionstreet
 

More from deepalishinkar1 (20)

PPTX
data structure stack appplication in python
deepalishinkar1
 
PPTX
Stack application in infix to prefix expression
deepalishinkar1
 
PPTX
Data Structure Stack operation in python
deepalishinkar1
 
PDF
Web application on menu card qrcode generator.pdf
deepalishinkar1
 
PPTX
Django model create a table in django web framework
deepalishinkar1
 
PPTX
TO DO APP USING STREAMLIT PYTHON PROJECT
deepalishinkar1
 
PPTX
basic concepts of object oriented in python
deepalishinkar1
 
PDF
Inheritance and polymorphism oops concepts in python
deepalishinkar1
 
PPTX
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
deepalishinkar1
 
PPTX
File Operations in python Read ,Write,binary file etc.
deepalishinkar1
 
PDF
How to create a django project procedure
deepalishinkar1
 
PDF
Virtual environment in python on windows / linux os
deepalishinkar1
 
PPTX
Operators in python
deepalishinkar1
 
PPTX
Data handling in python
deepalishinkar1
 
PDF
Practical approach on numbers system and math module
deepalishinkar1
 
PDF
Demonstration on keyword
deepalishinkar1
 
PPTX
Numbers and math module
deepalishinkar1
 
PPTX
Basic concepts of python
deepalishinkar1
 
PPTX
Introduction to python
deepalishinkar1
 
PDF
Set methods in python
deepalishinkar1
 
data structure stack appplication in python
deepalishinkar1
 
Stack application in infix to prefix expression
deepalishinkar1
 
Data Structure Stack operation in python
deepalishinkar1
 
Web application on menu card qrcode generator.pdf
deepalishinkar1
 
Django model create a table in django web framework
deepalishinkar1
 
TO DO APP USING STREAMLIT PYTHON PROJECT
deepalishinkar1
 
basic concepts of object oriented in python
deepalishinkar1
 
Inheritance and polymorphism oops concepts in python
deepalishinkar1
 
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
deepalishinkar1
 
File Operations in python Read ,Write,binary file etc.
deepalishinkar1
 
How to create a django project procedure
deepalishinkar1
 
Virtual environment in python on windows / linux os
deepalishinkar1
 
Operators in python
deepalishinkar1
 
Data handling in python
deepalishinkar1
 
Practical approach on numbers system and math module
deepalishinkar1
 
Demonstration on keyword
deepalishinkar1
 
Numbers and math module
deepalishinkar1
 
Basic concepts of python
deepalishinkar1
 
Introduction to python
deepalishinkar1
 
Set methods in python
deepalishinkar1
 
Ad

Recently uploaded (20)

PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
PPTX
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PPTX
Big Data and Data Science hype .pptx
SUNEEL37
 
PPT
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PPTX
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
Big Data and Data Science hype .pptx
SUNEEL37
 
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Thermal runway and thermal stability.pptx
godow93766
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
MRRS Strength and Durability of Concrete
CivilMythili
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Ad

steps for template in django for project

  • 2. TEMPLATE  A template in Django is basically written in HTML in a .html file.  Django framework efficiently handles and generates dynamic HTML web pages that are visible to the end-user.  Django mainly functions with a backend so, in order to provide a frontend and provide a layout to our website, we use templates.
  • 3. TEMPLATE  In current project, we will create a single template directory/folder that will contain all html files and that can be spread over the entire project for simplicity.  Create a folder/directory in command prompt on your project path using DOS (Disk Operating System) command md (make directory)  Example : (djangowork) C:UsersLenovoweekdays_django_batchtemplate_inheritance>md template Project path
  • 4. TEMPLATE  Add template in settings.py file,Write following commands,line no.14 and 17 Variable_ name folder_name Add varaiable name here
  • 5. DJANGO TEMPLATE LANGUAGE  A Django template is a text document or a Python string marked-up using the Django template language.  Some constructs are recognized and interpreted by the template engine.  A template contains variables, which get replaced with values when the template is evaluated, and tags, which control the logic of the template.  A template is rendered with a context. Rendering replaces variables with their values, which are looked up in the context, and executes tags. Everything else is output as is.
  • 6. DJANGO TEMPLATE LANGUAGE  The syntax of the Django template language involves four constructs. 1. Variable  A variable outputs a value from the context, which is a dict-like object mapping keys to values.  Variables are surrounded by {{ }} like this .  Use a dot (.) to access attributes of a variable.  In html file, we write : <h1>My name is {{firstname}} {{lastname}}</h1> In views .py file create context variable as a dictionary. With context {‘firstname’:’Deepali’ ‘lastname’:’Shinkar’} this template renders to : <h1>My name is Deepali Shinkar</h1> Use a dot (.) to access attributes of a variable.
  • 7. DJANGO TEMPLATE LANGUAGE 2. Filter When we need to modify variable before displaying ,we can use filter pipe ‘|’ is used to apply filter. Syntax : {{variable | filter}} Example :{{firstname | upper}} Some of filters take argument : Syntax : {{variable | filter : argument}}
  • 8. DJANGO TEMPLATE LANGUAGE  Float Format :When used without argument rounds a floating point number to one decimal place but only if there is a decimal part to be displayed.  Example :  56.24321 ---{{value | floatformat}} -56.2  56.00 ---{{value | floatformat}} -56  56.3700 ---{{value | floatformat}} -56.4  56.24321 ---{{value | floatformat:2}} -56.24
  • 9. DJANGO TEMPLATE LANGUAGE  3.Tags  Tags provide arbitrary logic in the rendering process.  Tags are surrounded by {%%} like this. Examples :  Some tags require beginning and ending tags. {% csrf_token %} {% url ‘add’ %} {% includes ‘base.html’ %} etc.
  • 10. DJANGO TEMPLATE LANGUAGE  Some tags require beginning and ending tags. Like this  If tag : It executes a variable and if that variable is true then execute html tag inside a if body. Syntax :  For tag : Evaluate a for loop any number of times which is depend on iterable object. Syntax : {% if variable or condition %} Html tags {% endif %} {% for variable in iterable_object %} {{variable}} {% endfor %}