0% found this document useful (0 votes)
7 views

Chapter Three Django Templates System

Uploaded by

africanoo mahaz
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Chapter Three Django Templates System

Uploaded by

africanoo mahaz
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter Three:

Django Template
System
BY:Eng Mohamed Ahmed Mohamed
Introduction

Django provides a convenient way to generate


dynamic HTML pages by using its template system.

A template consists of static parts of the desired


HTML output as well as some special syntax
describing how dynamic content will be inserted.
Django Template Configuration
To configure the template system, we have to provide some entries in
settings.py file.

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',

'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Function performed by
templates tags
Display Logic Loop Control Block Declaration

{% if %} {% for x in y {% block
... %} content %}
{% endif ... ...
%} {% endfor %} {% endblock %}

Content Import Inheritance

{% include {% extends
"header.html" "base.html"
%} %}
Filters

Filters look like this: {{ name|lower }}. This displays


the value of the {{ name }} variable after being
filtered through the lower filter, which converts text to
lowercase.
Filters

01 {{string|truncatewords:80}}

03 To store empty values as NULL in


database

02 {{string|lower}}

Converts the string to lowercase.

{{string|escape|linebreaks}}

Escapes string contents, then converts


line breaks to tags.You can also set the
default for a variable.
Create Simple Template

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Basic Site Template</title>
</head>

<body>
<h1>{{ title }}</h1>
<p>{{ cal }}</p>
</body>
</html>
Thank You
•Question

•And

•Answers

You might also like