Pearson Education, Inc., 2009. — 380 p.
Several Django books are already on the market, but this differs from most due to focusing equally on three areas: Django basics, a variety of example applications, and advanced Django topics. It was an attamp to make this the most well-rounded book on the subject, one you find useful regardless of background, and which will give you a complete picture of the framework and what you can do with it.
Where Web Frameworks Come From
A Better Way
We’re Not in Kansas Anymore
Web Development Is Better with Python and Django
Getting StartedPractical Python for DjangoPython Skills Are Django Skills
Getting Started: Python’s Interactive Interpreter
Python Basics
Comments
Variables and Assignment
Operators
Python Standard Types
Object Boolean Values
Numbers
Numeric Operators
Numeric Built-in and Factory Functions
Sequences and Iterables
Lists
Strings
Sequence Built-ins and Factory Functions
Mapping Type: Dictionaries
Standard Type Summary
Flow Control
Conditionals
Loops
Exception Handling
The finally Clause
Throwing Exceptions with raise
Files
Functions
Declaring and Calling Functions
Functions Are First-Class Objects
Anonymous Functions
*args and **kwargs
Decorators
Object-Oriented Programming
Class Definitions
Instantiation
Subclassing
Inner Classes
Regular Expressions
There module
Searching Versus Matching
Common Gotchas
Single-Item Tuples
Modules
Mutability
Constructor Versus Initializer
Coding Style (PEP and Beyond)
Indent Four Spaces
Use Spaces and Not Tabs
Don’t Write Single-Line Suites
on the Same Line as the Header
Create Documentation Strings (aka docstrings)
Django for the Impatient: Building a BlogCreating the Project
Running the Development Server
Creating the Blog Application
Designing Your Model
Setting Up the Database
Using a Database Server
Using SQLite
Creating the Tables
Setting Up the Automatic admin Application
Trying Out the admin
Making Your Blog’s Public Side
Creating a Template
Creating a View Function
Creating a URL Pattern
Finishing Touches
Template Niceties
Date-Based Ordering
Timestamp Formatting Via a Template Filter
Starting OutDynamic Web Site Basics
Communication: HTTP, URLs, Requests, Responses
Data Storage: SQL and Relational
Databases
Presentation: Rendering Templates into
HTML and Other Formats
Putting It All Together
Understanding Models, Views, and Templates
Separating the Layers (MVC)
Models
Views
Templates
Overall Django Architecture
Core Philosophies of Django
Django Tries to Be Pythonic
Don’t Repeat Yourself (DRY)
Loose Coupling and Flexibility
Rapid Development
Django in DepthDefining and Using ModelsDefining Models
Why Use an ORM?
Django’s Rich Field Types
Relationships Between Models
Model Inheritance
Meta Inner Class
Admin Registration and Options
Using Models
Creating and Updating Your Database
Using manage.py
Query Syntax
Utilizing SQL Features Django Doesn’t
Provide
URLs, HTTP Mechanisms, and ViewsURLs
Introduction to URLconfs
Replacing Tuples with URL
Using Multiple patterns Objects
Including Other URL Files with include
Function Objects Versus Function-Name Strings
Modeling HTTP: Requests, Responses, and Middleware
Request Objects
Response Objects
Middleware
Views/Logic
Just Python Functions
Generic Views
Semi-generic Views
Custom Views
Templates and Form ProcessingTemplates
Understanding Contexts
Template Language Syntax
Forms
Defining Forms
Filling Out Forms
Validation and Cleaning
Form Display
Widgets
Django Applications by ExamplePhoto GalleryThe Model
Preparing for File Uploads
Installing PIL
Testing ImageField
Building Our Custom File Field
Initialization
Adding Attributes to the Field
Saving and Deleting the Thumbnail
Using ThumbnailImageField
Setting Up DRY URLs
The Item App’s URL Layout
Tying It All Together with Templates
Content Management SystemWhat’s a CMS?
The Un-CMS: Flatpages
Enabling the Flatpages App
Flatpage Templates
Testing It Out
Beyond Flatpages: A Simple Custom CMS
Making the Model
Imports
Completing the Model
Controlling Which Stories Are Viewed
Working with Markdown
URL Patterns in urls.py
Admin Views
Displaying Content Via Generic Views
Template Layout
Displaying Stories
Adding Search
Managing Users
Supporting Workflow
Possible Enhancements
LiveblogWhat Exactly Is Ajax?
Why Ajax Is Useful
Planning the Application
Choosing an Ajax Library
Laying Out the Application
Putting the Ajax In
The Basics
The X in Ajax (Or XML Versus JSON)
Installing the JavaScript Library
Setting Up and Testing jQuery
Creating the View Function
Using the View Function Via JavaScript
PastebinDefining the Model
Creating the Templates
Designing the URLs
Trying It Out
Limiting Number of Recent Pastes Displayed
Syntax Highlighting
Cleanup Via Cron Job
Advanced Django Techniques and FeaturesAdvanced Django ProgrammingCustomizing the Admin
Changing Layout and Style Using Fieldsets
Extending the Base Templates
Adding New Views
Authentication Decorators
Using Syndication
The Feed Class
Giving the Feed a URL
Doing More with Feeds
Generating Downloadable Files
Nagios Configuration Files
vCard
Comma-Separated Value (CSV)
Charts and Graphs Using PyCha
Enhancing Django’s ORM with Custom Managers
Changing the Default Set of Objects
Adding New Manager Methods
Extending the Template System
Simple Custom Template Tags
Inclusion Tags
Custom Filters
More Complex Custom Template Tags
Alternative Templating
Advanced Django DeploymentWriting Utility Scripts
Cronjobs for Cleanup
Data Import/Export
Customizing the Django Codebase Itself
Caching
A Basic Caching Recipe
Caching Strategies
Caching Backend Types
Testing Django Applications
Doctest Basics
Unittest Basics
Running Tests
Testing Models
Testing Your Entire Web App
Testing the Django Codebase Itself
AppendicesCommand Line BasicsPutting the Command in Command Line
Options and Arguments
Pipes and Redirection
Environment Variables
The Path
Installing and Running DjangoPython
Mac OS X
Unix/Linux
Windows
Updating Your Path
Testing
Optional Add-ons
Django
Packaged Releases
Development Version
Installation
Testing
Web Server
The Built-In Server: Not for Production
The Standard Approach: Apache and
mod_python
The Flexible Alternative: WSGI
Another Approach: Flup and FastCGI
SQL Database
SQLite
PostgreSQL
MySQL
Oracle
Other Databases
Tools for Practical Django DevelopmentVersion Control
The Trunk and Branches
Merging
Centralized Version Control
Decentralized Version Control
Version Control for Your Project
Project Management Software
Trac
Text Editors
Emacs
Vim
TextMate
Eclipse
Finding, Evaluating, and Using DjangoApplications
Where to Look for Applications
How to Evaluate Applications
How to Use Applications
Sharing Your Own Application
Django on the Google App EngineWhy the App Engine Matters
Pure Google App Engine Applications
Limitations of the App Engine Framework
Google App Engine Helper for Django
Getting the SDK and the Helper
More on the Helper
Integrating the App Engine
Copying the App Engine Code to Your Project
Integrating the App Engine Helper
Porting Your Application to App Engine
Taking a Test Drive
Adding Data
Creating a New Django Application That Runs on App Engine
Online Resources
Getting Involved in the Django ProjectColophon