The Definitive Guide to Django

Web Development Done Right

Adrian Holovaty, Jacob Kaplan-Moss

Publisher: Apress, 2008, 447 pages

ISBN: 1-59059-725-7

Keywords: Python, Web Programming, Content Management

Last modified: Nov. 9, 2008, 11:42 a.m.

Django is a framework that saves you time and makes Web development a joy.

Django, the Python–based equivalent to the Ruby on Rails web development framework, is presently one of the hottest topics in web development today. In The Definitive Guide to Django: Web Development Done Right, Adrian Holovaty, one of Django’s creators, and Django lead developer Jacob Kaplan–Moss show you how they use this framework to create award–winning web sites. Over the course of three parts, they guide you through the creation of a web application reminiscent of chicagocrime.org.

The first part of the book introduces Django fundamentals like installation and configuration. You’ll learn about creating the components that power a Django–driven web site. The second part delves into the more sophisticated features of Django, like outputting non–HTML content (such as RSS feeds and PDFs), plus caching and user management. The third part serves as a detailed reference to Django’s many configuration options and commands. The book even includes seven appendixes for looking up configurations options and commands. In all, this book provides the ultimate tutorial and reference to the popular Django framework.

  • PART 1: Getting Started
    • CHAPTER 1 Introduction to Django
      • What Is a Web Framework?
      • The MVC Design Pattern
      • Django’s History
      • How to Read This Book
        • Required Programming Knowledge
        • Required Python Knowledge
        • New Django Features
        • Getting Help
      • What’s Next?
    • CHAPTER 2 Getting Started
      • Installing Python
      • Installing Django
        • Installing an Official Release
        • Installing Django from Subversion
      • Setting Up a Database
        • Using Django with PostgreSQL
        • Using Django with SQLite 3
        • Using Django with MySQL
        • Using Django Without a Database
      • Starting a Project
        • The Development Server
      • What’s Next
    • CHAPTER 3 The Basics of Dynamic Web Pages
      • Your First View: Dynamic Content
      • Mapping URLs to Views
      • How Django Processes a Request
        • How Django Processes a Request: Complete Details
      • URLconfs and Loose Coupling
      • 404 Errors
      • Your Second View: Dynamic URLs
        • A Word About Pretty URLs
        • Wildcard URLpatterns
      • Django’s Pretty Error Pages
      • What’s Next?
    • CHAPTER 4 The Django Template System
      • Template System Basics
      • Using the Template System
        • Creating Template Objects
        • Rendering a Template
        • Multiple Contexts, Same Template
        • Context Variable Lookup
        • Playing with Context Objects
      • Basic Template Tags and Filters
        • Tags
        • Filters
      • Philosophies and Limitations
      • Using Templates in Views
      • Template Loading
        • render_to_response()
        • The locals() Trick
        • Subdirectories in get_template()
        • The include Template Tag
      • Template Inheritance
      • What’s Next?
    • CHAPTER 5 Interacting with a Database: Models
      • The “Dumb”Way to Do Database Queries in Views
      • The MTV Development Pattern
      • Configuring the Database
      • Your First App
      • Defining Models in Python
      • Your First Model
      • Installing the Model
      • Basic Data Access
      • Adding Model String Representations
      • Inserting and Updating Data
      • Selecting Objects
        • Filtering Data
        • Retrieving Single Objects
        • Ordering Data
        • Chaining Lookups
        • Slicing Data
      • Deleting Objects
      • Making Changes to a Database Schema
        • Adding Fields
        • Removing Fields
        • Removing Many-to-Many Fields
        • Removing Models
      • What’s Next?
    • CHAPTER 6 The Django Administration Site
      • Activating the Admin Interface
      • Using the Admin Interface
        • Users, Groups, and Permissions
      • Customizing the Admin Interface
      • Customizing the Admin Interface’s Look and Feel
      • Customizing the Admin Index Page
      • When and Why to Use the Admin Interface
      • What’s Next?
    • CHAPTER 7 Form Processing
      • Search
      • The "Perfect Form"
      • Creating a Feedback Form
      • Processing the Submission
      • Custom Validation Rules
      • A Custom Look and Feel
      • Creating Forms from Models
      • What’s Next?
    • CHAPTER 8 Advanced Views and URLconfs
      • URLconf Tricks
        • Streamlining Function Imports
        • Using Multiple View Prefixes
        • Special-Casing URLs in Debug Mode
        • Using Named Groups
        • Understanding the Matching/Grouping Algorithm
        • Passing Extra Options to View Functions
        • Using Default View Arguments
        • Special-Casing Views
        • Capturing Text in URLs
        • Determining What the URLconf Searches Against
      • Including Other URLconfs
        • How Captured Parameters Work with include()
        • How Extra URLconf Options Work with include()
      • What’s Next?
  • PART 2: Django’s Subframeworks
    • CHAPTER 9 Generic Views
      • Using Generic Views
      • Generic Views of Objects
      • Extending Generic Views
        • Making “Friendly” Template Contexts
        • Adding Extra Context
        • Viewing Subsets of Objects
        • Complex Filtering with Wrapper Functions
        • Performing Extra Work
      • What’s Next?
    • CHAPTER 10 Extending the Template Engine
      • Template Language Review
      • RequestContext and Context Processors
        • django.core.context_processors.auth
        • django.core.context_processors.debug
        • django.core.context_processors.i18n
        • django.core.context_processors.request
        • Guidelines for Writing Your Own Context Processors
      • Inside Template Loading
      • Extending the Template System
        • Creating a Template Library
        • Writing Custom Template Filters
        • Writing Custom Template Tags
        • Shortcut for Simple Tags
        • Inclusion Tags
      • Writing Custom Template Loaders
      • Using the Built-in Template Reference
      • Configuring the Template System in Standalone Mode
      • What’s Next?
    • CHAPTER 11 Generating Non-HTML Content
      • The Basics: Views and MIME Types
      • Producing CSV
      • Generating PDFs
        • Installing ReportLab
        • Writing Your View
        • Complex PDFs
      • Other Possibilities
      • The Syndication Feed Framework
        • Initialization
        • A Simple Feed
        • A More Complex Feed
        • Specifying the Type of Feed
        • Enclosures
        • Language
        • URLs
        • Publishing Atom and RSS Feeds in Tandem
      • The Sitemap Framework
        • Installation
        • Initialization
        • Sitemap Classes
        • Shortcuts
        • Creating a Sitemap Index
        • Pinging Google
      • What’s Next?
    • CHAPTER 12 Sessions, Users, and Registration
      • Cookies
        • Getting and Setting Cookies
        • The Mixed Blessing of Cookies
      • Django’s Session Framework
        • Enabling Sessions
        • Using Sessions in Views
        • Setting Test Cookies
        • Using Sessions Outside of Views
        • When Sessions Are Saved
        • Browser-Length Sessions vs. Persistent Sessions
        • Other Session Settings
      • Users and Authentication
        • Enabling Authentication Support
        • Using Users
        • Logging In and Out
        • Limiting Access to Logged-in Users
        • Limiting Access to Users Who Pass a Test
        • Managing Users, Permissions, and Groups
        • Using Authentication Data in Templates
      • The Other Bits: Permissions, Groups, Messages, and Profiles
        • Permissions
        • Groups
        • Messages
        • Profiles
      • What’s Next?
    • CHAPTER 13 Caching
      • Setting Up the Cache
        • Memcached
        • Database Caching
        • Filesystem Caching
        • Local-Memory Caching
        • Simple Caching (for Development)
        • Dummy Caching (for Development)
        • CACHE_BACKEND Arguments
      • The Per-Site Cache
      • The Per-View Cache
        • Specifying Per-View Cache in the URLconf
      • The Low-Level Cache API
      • Upstream Caches
        • Using Vary Headers
        • Other Cache Headers
      • Other Optimizations
      • Order of MIDDLEWARE_CLASSES
      • What’s Next?
    • CHAPTER 14 Other Contributed Subframeworks
      • The Django Standard Library
      • Sites
        • Scenario 1: Reusing Data on Multiple Sites
        • Scenario 2: Storing Your Site Name/Domain in One Place
        • How to Use the Sites Framework
        • The Sites Framework’s Capabilities
        • CurrentSiteManager
        • How Django Uses the Sites Framework
      • Flatpages
        • Using Flatpages
        • Adding, Changing, and Deleting Flatpages
        • Using Flatpage Templates
      • Redirects
        • Using the Redirects Framework
        • Adding, Changing, and Deleting Redirects
      • CSRF Protection
        • A Simple CSRF Example
        • A More Complex CSRF Example
        • Preventing CSRF
      • Form Tools
        • django.contrib.formtools.preview
        • Using FormPreview
      • Humanizing Data
        • apnumber
        • intcomma
        • intword
        • ordinal
      • Markup Filters
      • What’s Next?
    • CHAPTER 15 Middleware
      • What’s Middleware?
      • Middleware Installation
      • Middleware Methods
        • Initializer: __init__(self)
        • Request Preprocessor: process_request(self, request)
        • View Preprocessor: process_view(self, request, view, args, kwargs)
        • Response Postprocessor: process_response(self, request, response)
        • Exception Postprocessor: process_exception(self, request, exception)
      • Built-in Middleware
        • Authentication Support Middleware
        • "Common" Middleware
        • Compression Middleware
        • Conditional GET Middleware
        • Reverse Proxy Support (X-Forwarded-For Middleware)
        • Session Support Middleware
        • Sitewide Cache Middleware
        • Transaction Middleware
        • "X-View" Middleware
      • What’s Next?
    • CHAPTER 16 Integrating with Legacy Databases and Applications
      • Integrating with a Legacy Database
        • Using inspectdb
        • Cleaning Up Generated Models
      • Integrating with an Authentication System
        • Specifying Authentication Back-Ends
        • Writing an Authentication Back-End
      • Integrating with Legacy Web Applications
      • What’s Next?
    • CHAPTER 17 Extending Django’s Admin Interface
      • The Zen of Admin . 242
        • "Trusted users . . ."
        • ". . . editing . . ."
        • ". . . structured content"
        • Full Stop
      • Customizing Admin Templates
        • Custom Model Templates
        • Custom JavaScript
      • Creating Custom Admin Views
      • Overriding Built-in Views
      • What’s Next?
    • CHAPTER 18 Internationalization
      • Specifying Translation Strings in Python Code
        • Standard Translation Functions
        • Marking Strings As No-op
        • Lazy Translation
        • Pluralization
      • Specifying Translation Strings in Template Code
      • Creating Language Files
        • Creating Message Files
        • Compiling Message Files
      • How Django Discovers Language Preference
      • The set_language Redirect View
      • Using Translations in Your Own Projects
      • Translations and JavaScript
        • The javascript_catalog View
        • Using the JavaScript Translation Catalog
        • Creating JavaScript Translation Catalogs
      • Notes for Users Familiar with gettext
      • What’s Next?
    • CHAPTER 19 Security
      • The Theme of Web Security
      • SQL Injection
        • The Solution
      • Cross-Site Scripting
        • The Solution
      • Cross-Site Request Forgery
      • Session Forging/Hijacking
        • The Solution
      • Email Header Injection
        • The Solution
      • Directory Traversal
        • The Solution
      • Exposed Error Messages
        • The Solution
      • A Final Word on Security
      • What’s Next?
    • CHAPTER 20 Deploying Django
      • Shared Nothing
      • A Note on Personal Preferences
      • Using Django with Apache and mod_python
        • Basic Configuration
        • Running Multiple Django Installations on the Same Apache Instance
        • Running a Development Server with mod_python
        • Serving Django and Media Files from the Same Apache Instance
        • Error Handling
        • Handling a Segmentation Fault
      • Using Django with FastCGI
        • FastCGI Overview
        • Running Your FastCGI Server
        • Using Django with Apache and FastCGI
        • FastCGI and lighttpd
        • Running Django on a Shared-Hosting Provider with Apache
      • Scaling
        • Running on a Single Server
        • Separating Out the Database Server
        • Running a Separate Media Server
        • Implementing Load Balancing and Redundancy
        • Going Big
      • Performance Tuning
        • There’s No Such Thing As Too Much RAM
        • Turn Off Keep-Alive
        • Use Memcached
        • Use Memcached Often
        • Join the Conversation
      • What’s Next?
  • PART 3: Appendixes
    • APPENDIX A Case Studies
      • Cast of Characters
      • Why Django?
      • Getting Started
      • Porting Existing Code
      • How Did It Go?
      • Team Structure
      • Deployment
    • APPENDIX B Model Definition Reference
      • Fields
        • Field Name Restrictions
        • AutoField
        • BooleanField
        • CharField
        • CommaSeparatedIntegerField
        • DateField
        • DateTimeField
        • EmailField
        • FileField
        • FilePathField
        • FloatField
        • ImageField
        • IntegerField
        • IPAddressField
        • NullBooleanField
        • PhoneNumberField
        • PositiveIntegerField
        • PositiveSmallIntegerField
        • SlugField
        • SmallIntegerField
        • TextField
        • TimeField
        • URLField
        • USStateField
        • XMLField
      • Universal Field Options
        • null
        • blank
        • choices
        • db_column
        • db_index
        • default
        • editable
        • help_text
        • primary_key
        • radio_admin
        • unique
        • unique_for_date
        • unique_for_month
        • unique_for_year
        • verbose_name
      • Relationships
        • Many-to-One Relationships
        • Many-to-Many Relationships
      • Model Metadata Options
        • db_table
        • db_tablespace
        • get_latest_by
        • order_with_respect_to
        • ordering
        • permissions
        • unique_together
        • verbose_name
        • verbose_name_plural
      • Managers
        • Manager Names
        • Custom Managers
      • Model Methods
        • __str__
        • get_absolute_url
        • Executing Custom SQL
        • Overriding Default Model Methods
      • Admin Options
        • date_hierarchy
        • fields
        • js
        • list_display
        • list_display_links
        • list_filter
        • list_per_page
        • list_select_related
        • ordering
        • save_as
        • save_on_top
        • search_fields
    • APPENDIX C Database API Reference
      • Creating Objects
        • What Happens When You Save?
        • Autoincrementing Primary Keys
      • Saving Changes to Objects
      • Retrieving Objects
      • Caching and QuerySets
      • Filtering Objects
        • Chaining Filters
        • Limiting QuerySets
        • Query Methods That Return New QuerySets
        • QuerySet Methods That Do Not Return QuerySets
      • Field Lookups
        • exact
        • iexact
        • contains
        • icontains
        • gt, gte, lt, and lte
        • in
        • startswith
        • istartswith
        • endswith and iendswith
        • range
        • year, month, and day
        • isnull
        • search
        • The pk Lookup Shortcut
      • Complex Lookups with Q Objects
      • Related Objects
        • Lookups That Span Relationships
        • Foreign Key Relationships
        • "Reverse" Foreign Key Relationships
        • Many-to-Many Relationships
        • Queries over Related Objects
      • Deleting Objects
      • Extra Instance Methods
        • get_FOO_display()
        • get_next_by_FOO(**kwargs) and get_previous_by_FOO(**kwargs)
        • get_FOO_filename()
        • get_FOO_url()
        • get_FOO_size()
        • save_FOO_file(filename, raw_contents)
        • get_FOO_height() and get_FOO_width()
      • Shortcuts
        • get_object_or_404()
        • get_list_or_404()
      • Falling Back to Raw SQL
    • APPENDIX D Generic View Reference
      • Common Arguments to Generic Views
      • "Simple" Generic Views
        • Rendering a Template
        • Redirecting to Another URL
      • List/Detail Generic Views
        • Lists of Objects
        • Detail Views
      • Date-Based Generic Views
        • Archive Index
        • Year Archives
        • Month Archives
        • Week Archives
        • Day Archives
        • Archive for Today
        • Date-Based Detail Pages
      • Create/Update/Delete Generic Views
        • Create Object View
        • Update Object View
        • Delete Object View
    • APPENDIX E Settings
      • What’s a Settings File?
        • Default Settings
        • Seeing Which Settings You’ve Changed
        • Using Settings in Python Code
        • Altering Settings at Runtime
        • Security
        • Creating Your Own Settings
      • Designating the Settings: DJANGO_SETTINGS_MODULE
        • The django-admin.py Utility
        • On the Server (mod_python)
      • Using Settings Without Setting DJANGO_SETTINGS_MODULE
        • Custom Default Settings
        • Either configure() or DJANGO_SETTINGS_MODULE Is Required
      • Available Settings
        • ABSOLUTE_URL_OVERRIDES
        • ADMIN_FOR
        • ADMIN_MEDIA_PREFIX
        • ADMINS
        • ALLOWED_INCLUDE_ROOTS
        • APPEND_SLASH
        • CACHE_BACKEND
        • CACHE_MIDDLEWARE_KEY_PREFIX
        • DATABASE_ENGINE
        • DATABASE_HOST
        • DATABASE_NAME
        • DATABASE_OPTIONS
        • DATABASE_PASSWORD
        • DATABASE_PORT
        • DATABASE_USER
        • DATE_FORMAT
        • TIMESTAMP_FORMAT
        • DEBUG
        • DEFAULT_CHARSET
        • DEFAULT_CONTENT_TYPE
        • DEFAULT_FROM_EMAIL
        • DISALLOWED_USER_AGENTS
        • EMAIL_HOST
        • EMAIL_HOST_PASSWORD
        • EMAIL_HOST_USER
        • EMAIL_PORT
        • EMAIL_SUBJECT_PREFIX
        • FIXTURE_DIRS
        • IGNORABLE_404_ENDS
        • IGNORABLE_404_STARTS
        • INSTALLED_APPS
        • INTERNAL_IPS
        • JING_PATH
        • LANGUAGE_CODE
        • LANGUAGES
        • MANAGERS
        • MEDIA_ROOT
        • MEDIA_URL
        • MIDDLEWARE_CLASSES
        • MONTH_DAY_FORMAT
        • PREPEND_WWW
        • PROFANITIES_LIST
        • ROOT_URLCONF
        • SECRET_KEY
        • SEND_BROKEN_LINK_EMAILS
        • SERIALIZATION_MODULES
        • SERVER_EMAIL
        • SESSION_COOKIE_AGE
        • SESSION_COOKIE_DOMAIN
        • SESSION_COOKIE_NAME
        • SESSION_COOKIE_SECURE
        • SESSION_EXPIRE_AT_BROWSER_CLOSE
        • SESSION_SAVE_EVERY_REQUEST
        • SITE_ID
        • TEMPLATE_CONTEXT_PROCESSORS
        • TEMPLATE_DEBUG
        • TEMPLATE_DIRS
        • TEMPLATE_LOADERS
        • TEMPLATE_STRING_IF_INVALID
        • TEST_RUNNER
        • TEST_DATABASE_NAME
        • TIME_FORMAT
        • TIME_ZONE
        • URL_VALIDATOR_USER_AGENT
        • USE_ETAGS
        • USE_I18N
        • YEAR_MONTH_FORMAT
    • APPENDIX F Built-in Template Tags and Filters
      • Built-in Tag Reference
        • block
        • comment
        • cycle
        • debug
        • extends
        • filter
        • firstof
        • for
        • if
        • ifchanged
        • ifequal
        • ifnotequal
        • include
        • load
        • now
        • regroup
        • spaceless
        • ssi
        • templatetag
        • url
        • widthratio
      • Built-in Filter Reference
        • add
        • addslashes
        • capfirst
        • center
        • cut
        • date
        • default
        • default_if_none
        • dictsort
        • dictsortreversed
        • divisibleby
        • escape
        • filesizeformat
        • first
        • fix_ampersands
        • floatformat
        • get_digit
        • join
        • length
        • length_is
        • linebreaks
        • linebreaksbr
        • linenumbers
        • ljust
        • lower
        • make_list
        • phone2numeric
        • pluralize
        • pprint
        • random
        • removetags
        • rjust
        • slice
        • slugify
        • stringformat
        • striptags
        • time
        • timesince
        • timeuntil
        • title
        • truncatewords
        • truncatewords_html
        • unordered_list
        • upper
        • urlencode
        • urlize
        • urlizetrunc
        • wordcount
        • wordwrap
        • yesno
    • APPENDIX G The django-admin Utility
      • Usage
      • Available Actions
        • adminindex [appname appname …]
        • createcachetable [tablename]
        • dbshell
        • diffsettings
        • dumpdata [appname appname …]
        • flush
        • inspectdb
        • loaddata [fixture fixture …]
        • reset [appname appname …]
        • runfcgi [option]
        • runserver [optional port number, or ipaddr:port]
        • shell
        • sql [appname appname …]
        • sqlall [appname appname …]
        • sqlclear [appname appname …]
        • sqlcustom [appname appname …]
        • sqlindexes [appname appname …]
        • sqlreset [appname appname …]
        • sqlsequencereset [appname appname …]
        • startapp [appname]
        • startproject [projectname]
        • syncdb
        • test
        • validate
      • Available Option
        • --settings
        • --pythonpath
        • --format
        • --help
        • --indent
        • --noinput
        • --noreload
        • --version
        • --verbosity
        • --adminmedia
    • APPENDIX H Request and Response Objects
      • HttpRequest
        • QueryDict Objects
        • A Complete Example
      • HttpResponse
        • Construction HttpResponses
        • Setting Headers
        • HttpResponse Subclasses
        • Returning Errors
        • Customizing the 404 (Page Not Found) View
        • Customizing the 500 (Server Error) View

Reviews

The Definitive Guide to Django

Reviewed by Roland Buresund

OK ***** (5 out of 10)

Last modified: June 12, 2008, 11:18 p.m.

Shows the underlying philosophy of Django and its community.

It starts of with a good introduction to web development and how to utilize Django. Then it starts to show advanced topics and unfortunately gloss over several deficiencies and explains that they are not important. The end of the book seems hurried through, and the whole experience leaves a bad taste.

It is OK as an introduction to Django, but it'll fail to win anyone experienced over.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required