Django 1.0 Template Development
eBook - ePub

Django 1.0 Template Development

  1. 272 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Django 1.0 Template Development

About this book

In Detail

Django is a high-level Python web application framework designed to support the rapid development of dynamic websites, web applications, and web services. Getting the most out of its template system allows programmers and designers to easily and efficiently output their content in a flexible, extendable, and maintainable manner.

This book will help you to master the Django template system. Built-in template tags and filters are explained with examples and usage notes, as well as information on building custom tags and filters to extend the system for your needs. You will learn to use inheritance to create modular templates that are easy to maintain. You will learn how to serve multiple templates from within the same Django project, with an example of how to serve different templates for a mobile version of your site without having to change any code in your views. Pagination, internationalization, caching, and customization of the automatic admin application are also covered.

A comprehensive, practical exploration of the usage and customization of Django's template system, including tutorials on pagination, caching, and internationalization.

Approach

This book is designed for readers who learn by doing and employs many examples and screenshots to let the reader dig in and start coding. This book isn't designed to be a reference; instead it has a practical, example-driven approach that teaches you by following along with the examples in the chapters.

When you have completed this book, you will fully understand how the template system works, how to extend it when you have specialized needs, and how to optimize the performance and usability of your content.

Who this book is for

This book is for web developers and template authors who want to fully understand and utilize the Django template system. The reader should have completed the introductory tutorials on the Django project's website and some experience with the framework will be very helpful. Basic knowledge of Python and HTML is assumed.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Django 1.0 Template Development

Scott Newman


Table of Contents

Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code for the book
Errata
Piracy
Questions
1. An Introduction to the Django Template System
What are templates?
Understanding the need for templates
Overview of the Django template system
Separating code from presentation
Helping designers and developers collaborate
Increasing maintainability
Template syntax
Modularity and reusability
Flexibility
Limitations
Critics of the system
Exploring how Django handles requests
Understanding the template system syntax
Context variable
Variables
Filters
Tags
Comments
Code note: Python dictionaries
How invalid variables are handled
Creating our demo application
Starting our application
Adding templates to our application
Adding variables to the view
Moving the logic into a separate template file
Using template filters
Using template tags to perform logical tests
Adding comments
Summary
2. Views, URLs, and Generic Views
An overview
Creating the application
Create the data model
Create the admin file
Configure the URLs
Add data in the admin application
Mapping URLs to views
Handling unmatched URL patterns
Splitting up the URL configurations
Creating views
Accepting the request object
Responding with an HTTP response
Responding with an exception
Putting the views together
Building the basic view
Cleaning up the error handling
Adding the template files
Adding the template to the view
Creating the list view and template
Using generic views to shorten development time
Simple generic views
Loading a template directly
Redirecting URLs
List/detail generic views
Replacing the list view
Replacing the detail view
Using the other generic views
Comparing views and generic views
Summary
3. Template Context
The context explained
Practicing working with the context
Using locals for prototyping
Adding, changing, and removing items in the context
Using the context values in your templates
Preventing method execution from templates
Handling invalid context variables
Cleaning up the view
Context rendering shortcuts
Using render_to_response()
Using render_to_string()
Context processors
Exploring the default context processors
Auth
Debug
Media
il8n
Configuring your project to use context processors
Configuring your views to use context processors
Using render_to_response with RequestContext
Using the context processors in our project
Writing your own context processor
Summary
4. Using the Built-In Tags and Filters
Built-in filter reference
add
addslashes
capfirst
center
cut
date
default
default_if_none
dictsort
dictsortreversed
divisibleby
escape
escapejs
filesizeformat
first
fix_ampersands
floatformat
force_escape
get_digit
iriencode
join
last
length
length_is
linebreaks
linebreaksbr
linenumbers
ljust
lower
make_list
phone2numeric
pluralize
pprint
random
removetags
rjust
safe
slice
slugify
stringformat
striptags
time
timesince
timeuntil
title
truncatewords
truncatewords_html
unordered_list
upper
urlencode
urlize
urlizetrunc
wordcount
wordwrap
yesno
Built-in tag reference
autoescape
block
comment
cycle
debug
extends
filter
firstof
for
forloop
if
ifchanged
ifequal
ifnotequal
include
load
now
regroup
spaceless
ssi
templatetag
url
widthratio
with
Summary
5. Loading and Inheriting Templates
Configuring the template system
Finding a home for the template files
Working with the template loaders
Loading templates manually
Choosing a template loader
Using the filesystem loader
Using the application directories loader
About the eggs template loader
Using the loaders together
Loading your template files
Setting up the error handling templates
Creating the error templates
Testing the error templates
Breaking templates into reusable pieces
Extending templates with inheritance
Using the block tag
Extending templates
Adding inheritance to the press application
Using multiple block tags
Adding template inheritance to our press release list
Inheriting from multiple child templates
Appending to blocks
Template strategy
Creating content placeholders
Extra JS
Extra style
Extra head content
Extra body tag attributes
Using include files
Using include
Using SSI
Summary
6. Serving Multiple Templates
Considering the different approaches
Serving mobile devices
Adapting content
Setting up our example
Serving printable pages
Creating site themes
Testing the template overrides
Serving different templates by domain name
Serving different sites with the development web server
Redirecting users to the mobile site (optional)
Detecting mobile devices
Writing the middleware
Checking only once
Installing the middleware
Summary
7. Custom Tags and Filters
Examining the built-in tags and filters
Template filters
Template tags
Writing your own template filters
Setting up a test application
Creating a home for our filter library
Template filter syntax
Loading templa...

Table of contents

  1. Django 1.0 Template Development

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Django 1.0 Template Development by Scott Newman in PDF and/or ePUB format, as well as other popular books in Computer Science & Information Technology. We have over one million books available in our catalogue for you to explore.