The Definitive Guide to Django: Web Development Done Right, Second Edition

Book description

'Lead developer Jacob Kaplan-Moss and Django creator Adrian Holovaty show you how they use this framework to create award-winning web sites by guiding you through the creation of a web application reminiscent of www.chicagocrime.org.

Table of contents

  1. Copyright
  2. About the Authors
  3. About the Technical Reviewer
  4. Acknowledgments
  5. Preface
  6. Introduction
  7. 1. Getting Started
    1. 1. Introduction to Django
      1. 1.1. What Is a Web Framework?
      2. 1.2. The MVC Design Pattern
      3. 1.3. Django's History
      4. 1.4. How to Read This Book
        1. 1.4.1. Required Programming Knowledge
        2. 1.4.2. Required Python Knowledge
        3. 1.4.3. Required Django Version
      5. 1.5. Getting Help
      6. 1.6. What's Next?
    2. 2. Getting Started
      1. 2.1. Installing Python
        1. 2.1.1. Python Versions
        2. 2.1.2. Installation
      2. 2.2. Installing Django
        1. 2.2.1. Installing an Official Release
        2. 2.2.2. Installing the Trunk Version
      3. 2.3. Testing the Django Installation
      4. 2.4. Setting Up a Database
        1. 2.4.1. Using Django with PostgreSQL
        2. 2.4.2. Using Django with SQLite 3
        3. 2.4.3. Using Django with MySQL
        4. 2.4.4. Using Django with Oracle
        5. 2.4.5. Using Django Without a Database
      5. 2.5. Starting a Project
        1. 2.5.1. Running the Development Server
      6. 2.6. What's Next?
    3. 3. Views and URLconfs
      1. 3.1. Your First Django-Powered Page: Hello World
        1. 3.1.1. Your First View
        2. 3.1.2. Your First URLconf
        3. 3.1.3. A Quick Note About 404 Errors
        4. 3.1.4. A Quick Note About the Site Root
      2. 3.2. How Django Processes a Request
      3. 3.3. Your Second View: Dynamic Content
      4. 3.4. URLconfs and Loose Coupling
      5. 3.5. Your Third View: Dynamic URLs
      6. 3.6. Django's Pretty Error Pages
      7. 3.7. What's Next?
    4. 4. Templates
      1. 4.1. Template-System Basics
      2. 4.2. Using the Template System
        1. 4.2.1. Creating Template Objects
        2. 4.2.2. Rendering a Template
        3. 4.2.3. Multiple Contexts, Same Template
        4. 4.2.4. Context Variable Lookup
          1. 4.2.4.1. Method-Call Behavior
          2. 4.2.4.2. How Invalid Variables Are Handled
        5. 4.2.5. Playing with Context Objects
      3. 4.3. Basic Template Tags and Filters
        1. 4.3.1. Tags
          1. 4.3.1.1. if/else
          2. 4.3.1.2. for
          3. 4.3.1.3. ifequal/ifnotequal
          4. 4.3.1.4. Comments
        2. 4.3.2. Filters
      4. 4.4. Philosophies and Limitations
      5. 4.5. Using Templates in Views
      6. 4.6. Template Loading
        1. 4.6.1. render_to_response()
        2. 4.6.2. The locals() Trick
        3. 4.6.3. Subdirectories in get_template()
        4. 4.6.4. The include Template Tag
      7. 4.7. Template Inheritance
      8. 4.8. What's Next?
    5. 5. Models
      1. 5.1. The "Dumb" Way to Do Database Queries in Views
      2. 5.2. The MTV (or MVC) Development Pattern
      3. 5.3. Configuring the Database
      4. 5.4. Your First App
      5. 5.5. Defining Models in Python
      6. 5.6. Your First Model
      7. 5.7. Installing the Model
      8. 5.8. Basic Data Access
      9. 5.9. Adding Model String Representations
      10. 5.10. Inserting and Updating Data
      11. 5.11. Selecting Objects
        1. 5.11.1. Filtering Data
        2. 5.11.2. Retrieving Single Objects
        3. 5.11.3. Ordering Data
        4. 5.11.4. Chaining Lookups
        5. 5.11.5. Slicing Data
        6. 5.11.6. Updating Multiple Objects in One Statement
      12. 5.12. Deleting Objects
      13. 5.13. What's Next?
    6. 6. The Django Admin Site
      1. 6.1. The django.contrib Packages
      2. 6.2. Activating the Admin Interface
      3. 6.3. Using the Admin Site
      4. 6.4. Adding Your Models to the Admin Site
      5. 6.5. How the Admin Site Works
      6. 6.6. Making Fields Optional
        1. 6.6.1. Making Date and Numeric Fields Optional
      7. 6.7. Customizing Field Labels
      8. 6.8. Custom ModelAdmin Classes
        1. 6.8.1. Customizing Change Lists
        2. 6.8.2. Customizing Edit Forms
      9. 6.9. Users, Groups, and Permissions
      10. 6.10. When and Why to Use the Admin Interface—And When Not To
      11. 6.11. What's Next?
    7. 7. Forms
      1. 7.1. Getting Data from the Request Object
        1. 7.1.1. Information About the URL
        2. 7.1.2. Other Information About the Request
        3. 7.1.3. Information About Submitted Data
      2. 7.2. A Simple Form-Handling Example
      3. 7.3. Improving Our Simple Form-Handling Example
      4. 7.4. Simple Validation
      5. 7.5. Making a Contact Form
      6. 7.6. Your First Form Class
        1. 7.6.1. Tying Form Objects into Views
        2. 7.6.2. Changing How Fields Are Rendered
        3. 7.6.3. Setting a Maximum Length
        4. 7.6.4. Setting Initial Values
        5. 7.6.5. Adding Custom Validation Rules
        6. 7.6.6. Specifying Labels
        7. 7.6.7. Customizing Form Design
      7. 7.7. What's Next?
  8. 2. Advanced Usage
    1. 8. Advanced Views and URLconfs
      1. 8.1. URLconf Tricks
        1. 8.1.1. Streamlining Function Imports
        2. 8.1.2. Using Multiple View Prefixes
        3. 8.1.3. Special-Casing URLs in Debug Mode
        4. 8.1.4. Using Named Groups
        5. 8.1.5. Understanding the Matching/Grouping Algorithm
        6. 8.1.6. Passing Extra Options to View Functions
          1. 8.1.6.1. Faking Captured URLconf Values
          2. 8.1.6.2. Making a View Generic
          3. 8.1.6.3. Giving a View Configuration Options
          4. 8.1.6.4. Understanding Precedence of Captured Values vs. Extra Options
        7. 8.1.7. Using Default View Arguments
        8. 8.1.8. Special-Casing Views
        9. 8.1.9. Capturing Text in URLs
        10. 8.1.10. Determining What the URLconf Searches Against
        11. 8.1.11. Higher-Level Abstractions of View Functions
        12. 8.1.12. Wrapping View Functions
      2. 8.2. Including Other URLconfs
        1. 8.2.1. How Captured Parameters Work with include()
        2. 8.2.2. How Extra URLconf Options Work with include()
      3. 8.3. What's Next?
    2. 9. Advanced Templates
      1. 9.1. Template Language Review
      2. 9.2. RequestContext and Context Processors
        1. 9.2.1. django.core.context_processors.auth
        2. 9.2.2. django.core.context_processors.debug
        3. 9.2.3. django.core.context_processors.i18n
        4. 9.2.4. django.core.context_processors.request
        5. 9.2.5. Guidelines for Writing Your Own Context Processors
      3. 9.3. Automatic HTML Escaping
        1. 9.3.1. How to Turn It Off
          1. 9.3.1.1. For Individual Variables
          2. 9.3.1.2. For Template Blocks
        2. 9.3.2. Notes
        3. 9.3.3. Automatic Escaping of String Literals in Filter Arguments
      4. 9.4. Inside Template Loading
      5. 9.5. Extending the Template System
        1. 9.5.1. Creating a Template Library
        2. 9.5.2. Writing Custom Template Filters
        3. 9.5.3. Writing Custom Template Tags
        4. 9.5.4. Writing the Compilation Function
        5. 9.5.5. Writing the Template Node
        6. 9.5.6. Registering the Tag
        7. 9.5.7. Setting a Variable in the Context
        8. 9.5.8. Parsing Until Another Template Tag
        9. 9.5.9. Parsing Until Another Template Tag and Saving Contents
        10. 9.5.10. Shortcut for Simple Tags
        11. 9.5.11. Inclusion Tags
      6. 9.6. Writing Custom Template Loaders
      7. 9.7. Configuring the Template System in Standalone Mode
      8. 9.8. What's Next?
    3. 10. Advanced Models
      1. 10.1. Related Objects
        1. 10.1.1. Accessing Foreign Key Values
        2. 10.1.2. Accessing Many-to-Many Values
      2. 10.2. Making Changes to a Database Schema
        1. 10.2.1. Adding Fields
        2. 10.2.2. Removing Fields
        3. 10.2.3. Removing Many-to-Many Fields
        4. 10.2.4. Removing Models
      3. 10.3. Managers
        1. 10.3.1. Adding Extra Manager Methods
        2. 10.3.2. Modifying Initial Manager QuerySets
      4. 10.4. Model Methods
      5. 10.5. Executing Raw SQL Queries
      6. 10.6. What's Next?
    4. 11. Generic Views
      1. 11.1. Using Generic Views
      2. 11.2. Generic Views of Objects
      3. 11.3. Extending Generic Views
        1. 11.3.1. Making "Friendly" Template Contexts
        2. 11.3.2. Adding Extra Context
        3. 11.3.3. Viewing Subsets of Objects
        4. 11.3.4. Complex Filtering with Wrapper Functions
        5. 11.3.5. Performing Extra Work
      4. 11.4. What's Next?
    5. 12. Deploying Django
      1. 12.1. Preparing Your Codebase for Production
        1. 12.1.1. Turning Off Debug Mode
        2. 12.1.2. Turning Off Template Debug Mode
        3. 12.1.3. Implementing a 404 Template
        4. 12.1.4. Implementing a 500 Template
        5. 12.1.5. Setting Up Error Alerts
        6. 12.1.6. Setting Up Broken Link Alerts
      2. 12.2. Using Different Settings for Production
      3. 12.3. DJANGO_SETTINGS_MODULE
      4. 12.4. Using Django with Apache and mod_python
        1. 12.4.1. Basic Configuration
        2. 12.4.2. Running Multiple Django Installations on the Same Apache Instance
        3. 12.4.3. Running a Development Server with mod_python
        4. 12.4.4. Serving Django and Media Files from the Same Apache Instance
        5. 12.4.5. Error Handling
        6. 12.4.6. Handling a Segmentation Fault
        7. 12.4.7. An Alternative: mod_wsgi
      5. 12.5. Using Django with FastCGI
        1. 12.5.1. FastCGI Overview
        2. 12.5.2. Running Your FastCGI Server
          1. 12.5.2.1. Stopping the FastCGI Daemon
        3. 12.5.3. Using Django with Apache and FastCGI
          1. 12.5.3.1. Specifying the Location of the FastCGI Server
          2. 12.5.3.2. Using mod_rewrite to Point URLs at FastCGI
        4. 12.5.4. FastCGI and lighttpd
          1. 12.5.4.1. Running Multiple Django Sites on One lighttpd Instance
        5. 12.5.5. Running Django on a Shared-Hosting Provider with Apache
          1. 12.5.5.1. Restarting the Spawned Server
      6. 12.6. Scaling
        1. 12.6.1. Running on a Single Server
        2. 12.6.2. Separating Out the Database Server
        3. 12.6.3. Running a Separate Media Server
        4. 12.6.4. Implementing Load Balancing and Redundancy
        5. 12.6.5. Going Big
      7. 12.7. Performance Tuning
        1. 12.7.1. There's No Such Thing As Too Much RAM
        2. 12.7.2. Turn Off Keep-Alive
        3. 12.7.3. Use Memcached
        4. 12.7.4. Use Memcached Often
        5. 12.7.5. Join the Conversation
      8. 12.8. What's Next?
  9. 3. Other Django Features
    1. 13. Generating Non-HTML Content
      1. 13.1. The Basics: Views and MIME Types
      2. 13.2. Producing CSV
      3. 13.3. Generating PDFs
        1. 13.3.1. Installing ReportLab
        2. 13.3.2. Writing Your View
        3. 13.3.3. Complex PDFs
      4. 13.4. Other Possibilities
      5. 13.5. The Syndication-Feed Framework
        1. 13.5.1. Initialization
        2. 13.5.2. A Simple Feed
        3. 13.5.3. A More Complex Feed
        4. 13.5.4. Specifying the Type of Feed
        5. 13.5.5. Enclosures
        6. 13.5.6. Language
        7. 13.5.7. URLs
        8. 13.5.8. Publishing Atom and RSS Feeds in Tandem
      6. 13.6. The Sitemap Framework
        1. 13.6.1. Installation
        2. 13.6.2. Initialization
        3. 13.6.3. Sitemap Classes
        4. 13.6.4. Shortcuts
          1. 13.6.4.1. FlatPageSitemap
          2. 13.6.4.2. GenericSitemap
        5. 13.6.5. Creating a Sitemap Index
        6. 13.6.6. Pinging Google
      7. 13.7. What's Next?
    2. 14. Sessions, Users, and Registration
      1. 14.1. Cookies
        1. 14.1.1. Getting and Setting Cookies
        2. 14.1.2. The Mixed Blessing of Cookies
      2. 14.2. Django's Session Framework
        1. 14.2.1. Enabling Sessions
        2. 14.2.2. Using Sessions in Views
        3. 14.2.3. Setting Test Cookies
        4. 14.2.4. Using Sessions Outside of Views
        5. 14.2.5. When Sessions Are Saved
        6. 14.2.6. Browser-Length Sessions vs. Persistent Sessions
        7. 14.2.7. Other Session Settings
      3. 14.3. Users and Authentication
        1. 14.3.1. Enabling Authentication Support
        2. 14.3.2. Using Users
        3. 14.3.3. Logging In and Out
        4. 14.3.4. Limiting Access to Logged-in Users
        5. 14.3.5. Limiting Access to Users Who Pass a Test
        6. 14.3.6. Managing Users, Permissions, and Groups
          1. 14.3.6.1. Creating Users
          2. 14.3.6.2. Changing Passwords
          3. 14.3.6.3. Handling Registration
        7. 14.3.7. Using Authentication Data in Templates
      4. 14.4. Permissions, Groups, and Messages
        1. 14.4.1. Permissions
        2. 14.4.2. Groups
        3. 14.4.3. Messages
      5. 14.5. What's Next?
    3. 15. Caching
      1. 15.1. Setting Up the Cache
        1. 15.1.1. Memcached
        2. 15.1.2. Database Caching
        3. 15.1.3. Filesystem Caching
        4. 15.1.4. Local-Memory Caching
        5. 15.1.5. Dummy Caching (for Development)
        6. 15.1.6. Using a Custom Cache Back-End
        7. 15.1.7. CACHE_BACKEND Arguments
      2. 15.2. The Per-Site Cache
      3. 15.3. The Per-View Cache
        1. 15.3.1. Specifying Per-View Cache in the URLconf
      4. 15.4. Template Fragment Caching
      5. 15.5. The Low-Level Cache API
      6. 15.6. Upstream Caches
      7. 15.7. Using Vary Headers
      8. 15.8. Controlling Cache: Using Other Headers
      9. 15.9. Other Optimizations
      10. 15.10. Order of MIDDLEWARE_CLASSES
      11. 15.11. What's Next?
    4. 16. django.contrib
      1. 16.1. The Django Standard Library
      2. 16.2. Sites
        1. 16.2.1. Scenario 1: Reusing Data on Multiple Sites
        2. 16.2.2. Scenario 2: Storing Your Site Name/Domain in One Place
        3. 16.2.3. How to Use the Sites Framework
        4. 16.2.4. The Sites Framework's Capabilities
          1. 16.2.4.1. Reusing Data on Multiple Sites
          2. 16.2.4.2. Associating Content with a Single Site
          3. 16.2.4.3. Hooking into the Current Site from Views
          4. 16.2.4.4. Getting the Current Domain for Display
        5. 16.2.5. CurrentSiteManager
        6. 16.2.6. How Django Uses the Sites Framework
      3. 16.3. Flatpages
        1. 16.3.1. Using Flatpages
        2. 16.3.2. Adding, Changing, and Deleting Flatpages
          1. 16.3.2.1. Via the Admin Interface
          2. 16.3.2.2. Via the Python API
        3. 16.3.3. Using Flatpage Templates
      4. 16.4. Redirects
        1. 16.4.1. Using the Redirects Framework
        2. 16.4.2. Adding, Changing, and Deleting Redirects
          1. 16.4.2.1. Via the Admin Interface
          2. 16.4.2.2. Via the Python API
      5. 16.5. CSRF Protection
        1. 16.5.1. A Simple CSRF Example
        2. 16.5.2. A More Complex CSRF Example
        3. 16.5.3. Preventing CSRF
          1. 16.5.3.1. Using the CSRF Middleware
          2. 16.5.3.2. Limitations of the CSRF Middleware
      6. 16.6. Humanizing Data
        1. 16.6.1. apnumber
        2. 16.6.2. intcomma
        3. 16.6.3. intword
        4. 16.6.4. ordinal
      7. 16.7. Markup Filters
      8. 16.8. What's Next?
    5. 17. Middleware
      1. 17.1. What's Middleware?
      2. 17.2. Middleware Installation
      3. 17.3. Middleware Methods
        1. 17.3.1. Initializer: __init__(self)
        2. 17.3.2. Request Preprocessor: process_request(self, request)
        3. 17.3.3. View Preprocessor: process_view(self, request, view, args, kwargs)
        4. 17.3.4. Response Postprocessor: process_response(self, request, response)
        5. 17.3.5. Exception Postprocessor: process_exception(self, request, exception)
      4. 17.4. Built-in Middleware
        1. 17.4.1. Authentication Support Middleware
        2. 17.4.2. "Common" Middleware
        3. 17.4.3. Compression Middleware
        4. 17.4.4. Conditional GET Middleware
        5. 17.4.5. Reverse Proxy Support (X-Forwarded-For Middleware)
        6. 17.4.6. Session Support Middleware
        7. 17.4.7. Sitewide Cache Middleware
        8. 17.4.8. Transaction Middleware
      5. 17.5. What's Next?
    6. 18. Integrating with Legacy Databases and Applications
      1. 18.1. Integrating with a Legacy Database
        1. 18.1.1. Using inspectdb
        2. 18.1.2. Cleaning Up Generated Models
      2. 18.2. Integrating with an Authentication System
        1. 18.2.1. Specifying Authentication Back-Ends
        2. 18.2.2. Writing an Authentication Back-End
      3. 18.3. Integrating with Legacy Web Applications
      4. 18.4. What's Next?
    7. 19. Internationalization
      1. 19.1. How to Specify Translation Strings
        1. 19.1.1. In Python Code
          1. 19.1.1.1. Standard Translation
          2. 19.1.1.2. Marking Strings As No-Op
          3. 19.1.1.3. Lazy Translation
          4. 19.1.1.4. Pluralization
        2. 19.1.2. In Template Code
        3. 19.1.3. Working with Lazy Translation Objects
          1. 19.1.3.1. Joining Strings: string_concat()
          2. 19.1.3.2. The allow_lazy() Decorator
      2. 19.2. How to Create Language Files
        1. 19.2.1. Message Files
        2. 19.2.2. Compiling Message Files
      3. 19.3. How Django Discovers Language Preference
      4. 19.4. Using Translations in Your Own Projects
      5. 19.5. The set_language Redirect View
      6. 19.6. Translations and JavaScript
        1. 19.6.1. The javascript_catalog View
        2. 19.6.2. Using the JavaScript Translation Catalog
        3. 19.6.3. Creating JavaScript Translation Catalogs
      7. 19.7. Notes for Users Familiar with gettext
      8. 19.8. gettext on Windows
      9. 19.9. What's Next?
    8. 20. Security
      1. 20.1. The Theme of Web Security
      2. 20.2. SQL Injection
        1. 20.2.1. The Solution
      3. 20.3. Cross-Site Scripting (XSS)
        1. 20.3.1. The Solution
      4. 20.4. Cross-Site Request Forgery
      5. 20.5. Session Forging/Hijacking
        1. 20.5.1. The Solution
      6. 20.6. E-mail Header Injection
        1. 20.6.1. The Solution
      7. 20.7. Directory Traversal
        1. 20.7.1. The Solution
      8. 20.8. Exposed Error Messages
        1. 20.8.1. The Solution
      9. 20.9. A Final Word on Security
      10. 20.10. What's Next?
  10. 4. Appendixes
    1. A. Model Definition Reference
      1. A.1. Fields
        1. A.1.1. AutoField
        2. A.1.2. BooleanField
        3. A.1.3. CharField
        4. A.1.4. CommaSeparatedIntegerField
        5. A.1.5. DateField
        6. A.1.6. DateTimeField
        7. A.1.7. DecimalField
        8. A.1.8. EmailField
        9. A.1.9. FileField
        10. A.1.10. FilePathField
        11. A.1.11. FloatField
        12. A.1.12. ImageField
        13. A.1.13. IntegerField
        14. A.1.14. IPAddressField
        15. A.1.15. NullBooleanField
        16. A.1.16. PositiveIntegerField
        17. A.1.17. PositiveSmallIntegerField
        18. A.1.18. SlugField
        19. A.1.19. SmallIntegerField
        20. A.1.20. TextField
        21. A.1.21. TimeField
        22. A.1.22. URLField
        23. A.1.23. XMLField
      2. A.2. Universal Field Options
        1. A.2.1. null
        2. A.2.2. blank
        3. A.2.3. choices
        4. A.2.4. db_column
        5. A.2.5. db_index
        6. A.2.6. db_tablespace
        7. A.2.7. default
        8. A.2.8. editable
        9. A.2.9. help_text
        10. A.2.10. primary_key
        11. A.2.11. unique
        12. A.2.12. unique_for_date
        13. A.2.13. unique_for_month
        14. A.2.14. unique_for_year
        15. A.2.15. verbose_name
      3. A.3. Relationships
        1. A.3.1. ForeignKey
        2. A.3.2. ManyToManyField
        3. A.3.3. OneToOneField
      4. A.4. Model Metadata Options
        1. A.4.1. abstract
        2. A.4.2. db_table
          1. A.4.2.1. Table names
        3. A.4.3. db_tablespace
        4. A.4.4. get_latest_by
        5. A.4.5. managed
        6. A.4.6. ordering
        7. A.4.7. proxy
        8. A.4.8. unique_together
        9. A.4.9. verbose_name
        10. A.4.10. verbose_name_plural
    2. B. Database API Reference
      1. B.1. Creating Objects
        1. B.1.1. What Happens When You Save?
        2. B.1.2. Autoincrementing Primary Keys
      2. B.2. Saving Changes to Objects
      3. B.3. Retrieving Objects
      4. B.4. Caching and QuerySets
      5. B.5. Filtering Objects
        1. B.5.1. Chaining Filters
        2. B.5.2. Limiting QuerySets
        3. B.5.3. Query Methods That Return New QuerySets
          1. B.5.3.1. filter(**lookup)
          2. B.5.3.2. exclude(**lookup)
          3. B.5.3.3. order_by(*fields)
          4. B.5.3.4. distinct()
          5. B.5.3.5. values(*fields)
          6. B.5.3.6. dates(field, kind, order)
          7. B.5.3.7. select_related()
        4. B.5.4. QuerySet Methods That Do Not Return QuerySets
          1. B.5.4.1. get(**lookup)
          2. B.5.4.2. create(**kwargs)
          3. B.5.4.3. get_or_create(**kwargs)
          4. B.5.4.4. count()
          5. B.5.4.5. in_bulk(id_list)
          6. B.5.4.6. latest(field_name=None)
      6. B.6. Field Lookups
        1. B.6.1. exact
        2. B.6.2. iexact
        3. B.6.3. contains
        4. B.6.4. icontains
        5. B.6.5. gt, gte, lt, and lte
        6. B.6.6. in
        7. B.6.7. startswith
        8. B.6.8. istartswith
        9. B.6.9. endswith and iendswith
        10. B.6.10. range
        11. B.6.11. year, month, and day
        12. B.6.12. isnull
        13. B.6.13. search
        14. B.6.14. The pk Lookup Shortcut
      7. B.7. Complex Lookups with Q Objects
      8. B.8. Related Objects
        1. B.8.1. Lookups That Span Relationships
        2. B.8.2. Foreign-Key Relationships
        3. B.8.3. "Reverse" Foreign-Key Relationships
        4. B.8.4. Many-to-Many Relationships
        5. B.8.5. Queries over Related Objects
      9. B.9. Deleting Objects
      10. B.10. Shortcuts
        1. B.10.1. get_object_or_404()
        2. B.10.2. get_list_or_404()
      11. B.11. Falling Back to Raw SQL
    3. C. Generic View Reference
      1. C.1. Common Arguments to Generic Views
      2. C.2. "Simple" Generic Views
        1. C.2.1. Rendering a Template
          1. C.2.1.1. Example
          2. C.2.1.2. Required Arguments
        2. C.2.2. Redirecting to Another URL
          1. C.2.2.1. Example
          2. C.2.2.2. Required Arguments
      3. C.3. List/Detail Generic Views
        1. C.3.1. Lists of Objects
          1. C.3.1.1. Example
          2. C.3.1.2. Required Arguments
          3. C.3.1.3. Optional Arguments
          4. C.3.1.4. Template Name
          5. C.3.1.5. Template Context
        2. C.3.2. Detail Views
          1. C.3.2.1. Example
          2. C.3.2.2. Required Arguments
          3. C.3.2.3. Optional Arguments
          4. C.3.2.4. Template Name
          5. C.3.2.5. Template Context
      4. C.4. Date-Based Generic Views
        1. C.4.1. Archive Index
          1. C.4.1.1. Example
          2. C.4.1.2. Required Arguments
          3. C.4.1.3. Optional Arguments
          4. C.4.1.4. Template Name
          5. C.4.1.5. Template Context
        2. C.4.2. Year Archives
          1. C.4.2.1. Example
          2. C.4.2.2. Required Arguments
          3. C.4.2.3. Optional Arguments
          4. C.4.2.4. Template Name
          5. C.4.2.5. Template Context
        3. C.4.3. Month Archives
          1. C.4.3.1. Example
          2. C.4.3.2. Required Arguments
          3. C.4.3.3. Optional Arguments
          4. C.4.3.4. Template Name
          5. C.4.3.5. Template Context
        4. C.4.4. Week Archives
          1. C.4.4.1. Example
          2. C.4.4.2. Required Arguments
          3. C.4.4.3. Optional Arguments
          4. C.4.4.4. Template Name
          5. C.4.4.5. Template Context
        5. C.4.5. Day Archives
          1. C.4.5.1. Example
          2. C.4.5.2. Required Arguments
          3. C.4.5.3. Optional Arguments
          4. C.4.5.4. Template Name
          5. C.4.5.5. Template Context
        6. C.4.6. Archive for Today
          1. C.4.6.1. Example
        7. C.4.7. Date-Based Detail Pages
          1. C.4.7.1. Example
          2. C.4.7.2. Required Arguments
          3. C.4.7.3. Optional Arguments
          4. C.4.7.4. Template Name
          5. C.4.7.5. Template Context
    4. D. Settings
      1. D.1. The Basics of Settings Files
        1. D.1.1. Default Settings
        2. D.1.2. Seeing Which Settings You've Changed
        3. D.1.3. Using Settings in Python Code
        4. D.1.4. Altering Settings at Runtime
        5. D.1.5. Security
        6. D.1.6. Creating Your Own Settings
      2. D.2. Designating the Settings: DJANGO_SETTINGS_MODULE
        1. D.2.1. The django-admin.py Utility
        2. D.2.2. On the Server (mod_python)
      3. D.3. Using Settings Without Setting DJANGO_SETTINGS_MODULE
        1. D.3.1. Custom Default Settings
        2. D.3.2. Either configure() or DJANGO_SETTINGS_MODULE Is Required
      4. D.4. Available Settings
        1. D.4.1. ABSOLUTE_URL_OVERRIDES
        2. D.4.2. ADMIN_MEDIA_PREFIX
        3. D.4.3. ADMINS
        4. D.4.4. ALLOWED_INCLUDE_ROOTS
        5. D.4.5. APPEND_SLASH
        6. D.4.6. CACHE_BACKEND
        7. D.4.7. CACHE_MIDDLEWARE_KEY_PREFIX
        8. D.4.8. DATABASE_ENGINE
        9. D.4.9. DATABASE_HOST
        10. D.4.10. DATABASE_NAME
        11. D.4.11. DATABASE_OPTIONS
        12. D.4.12. DATABASE_PASSWORD
        13. D.4.13. DATABASE_PORT
        14. D.4.14. DATABASE_USER
        15. D.4.15. DATE_FORMAT
        16. D.4.16. DATETIME_FORMAT
        17. D.4.17. DEBUG
        18. D.4.18. DEFAULT_CHARSET
        19. D.4.19. DEFAULT_CONTENT_TYPE
        20. D.4.20. DEFAULT_FROM_EMAIL
        21. D.4.21. DISALLOWED_USER_AGENTS
        22. D.4.22. EMAIL_HOST
        23. D.4.23. EMAIL_HOST_PASSWORD
        24. D.4.24. EMAIL_HOST_USER
        25. D.4.25. EMAIL_PORT
        26. D.4.26. EMAIL_SUBJECT_PREFIX
        27. D.4.27. FIXTURE_DIRS
        28. D.4.28. IGNORABLE_404_ENDS
        29. D.4.29. IGNORABLE_404_STARTS
        30. D.4.30. INSTALLED_APPS
        31. D.4.31. LANGUAGE_CODE
        32. D.4.32. LANGUAGES
        33. D.4.33. MANAGERS
        34. D.4.34. MEDIA_ROOT
        35. D.4.35. MEDIA_URL
        36. D.4.36. MIDDLEWARE_CLASSES
        37. D.4.37. MONTH_DAY_FORMAT
        38. D.4.38. PREPEND_WWW
        39. D.4.39. ROOT_URLCONF
        40. D.4.40. SECRET_KEY
        41. D.4.41. SEND_BROKEN_LINK_EMAILS
        42. D.4.42. SERIALIZATION_MODULES
        43. D.4.43. SERVER_EMAIL
        44. D.4.44. SESSION_COOKIE_AGE
        45. D.4.45. SESSION_COOKIE_DOMAIN
        46. D.4.46. SESSION_COOKIE_NAME
        47. D.4.47. SESSION_COOKIE_SECURE
        48. D.4.48. SESSION_EXPIRE_AT_BROWSER_CLOSE
        49. D.4.49. SESSION_SAVE_EVERY_REQUEST
        50. D.4.50. SITE_ID
        51. D.4.51. TEMPLATE_CONTEXT_PROCESSORS
        52. D.4.52. TEMPLATE_DEBUG
        53. D.4.53. TEMPLATE_DIRS
        54. D.4.54. TEMPLATE_LOADERS
        55. D.4.55. TEMPLATE_STRING_IF_INVALID
        56. D.4.56. TEST_DATABASE_NAME
        57. D.4.57. TEST_RUNNER
        58. D.4.58. TIME_FORMAT
        59. D.4.59. TIME_ZONE
        60. D.4.60. URL_VALIDATOR_USER_AGENT
        61. D.4.61. USE_ETAGS
        62. D.4.62. USE_I18N
        63. D.4.63. YEAR_MONTH_FORMAT
    5. E. Built-in Template Tags and Filters
      1. E.1. Built-in Tag Reference
        1. E.1.1. autoescape
        2. E.1.2. block
        3. E.1.3. comment
        4. E.1.4. cycle
        5. E.1.5. debug
        6. E.1.6. extends
        7. E.1.7. filter
        8. E.1.8. firstof
        9. E.1.9. for
        10. E.1.10. if
        11. E.1.11. ifchanged
        12. E.1.12. ifequal
        13. E.1.13. ifnotequal
        14. E.1.14. include
        15. E.1.15. load
        16. E.1.16. now
        17. E.1.17. regroup
        18. E.1.18. spaceless
        19. E.1.19. ssi
        20. E.1.20. templatetag
        21. E.1.21. url
        22. E.1.22. widthratio
        23. E.1.23. with
      2. E.2. Built-in Filter Reference
        1. E.2.1. add
        2. E.2.2. addslashes
        3. E.2.3. capfirst
        4. E.2.4. center
        5. E.2.5. cut
        6. E.2.6. date
        7. E.2.7. default
        8. E.2.8. default_if_none
        9. E.2.9. dictsort
        10. E.2.10. dictsortreversed
        11. E.2.11. divisibleby
        12. E.2.12. escape
        13. E.2.13. escapejs
        14. E.2.14. filesizeformat
        15. E.2.15. first
        16. E.2.16. fix_ampersands
        17. E.2.17. floatformat
        18. E.2.18. force_escape
        19. E.2.19. get_digit
        20. E.2.20. iriencode
        21. E.2.21. join
        22. E.2.22. last
        23. E.2.23. length
        24. E.2.24. length_is
        25. E.2.25. linebreaks
          1. E.2.25.1. linebreaksbr
        26. E.2.26. linenumbers
        27. E.2.27. ljust
        28. E.2.28. lower
        29. E.2.29. make_list
        30. E.2.30. phone2numeric
        31. E.2.31. pluralize
        32. E.2.32. pprint
        33. E.2.33. random
        34. E.2.34. removetags
        35. E.2.35. rjust
        36. E.2.36. safe
        37. E.2.37. safeseq
        38. E.2.38. slice
        39. E.2.39. slugify
        40. E.2.40. stringformat
        41. E.2.41. striptags
        42. E.2.42. time
        43. E.2.43. timesince
        44. E.2.44. timeuntil
        45. E.2.45. title
        46. E.2.46. truncatewords
        47. E.2.47. truncatewords_html
        48. E.2.48. unordered_list
        49. E.2.49. upper
        50. E.2.50. urlencode
        51. E.2.51. urlize
        52. E.2.52. urlizetrunc
        53. E.2.53. wordcount
        54. E.2.54. wordwrap
        55. E.2.55. yesno
    6. F. The django-admin Utility
      1. F.1. Usage
        1. F.1.1. Getting Runtime Help
        2. F.1.2. App Names
        3. F.1.3. Determining the Version
        4. F.1.4. Displaying Debug Output
      2. F.2. Available Subcommands
        1. F.2.1. cleanup
        2. F.2.2. compilemessages
          1. F.2.2.1. --locale
        3. F.2.3. createcachetable
        4. F.2.4. createsuperuser
        5. F.2.5. dbshell
        6. F.2.6. diffsettings
        7. F.2.7. dumpdata
        8. F.2.8. flush
        9. F.2.9. inspectdb
        10. F.2.10. loaddata <fixture fixture ...>
          1. F.2.10.1. What's a Fixture?
          2. F.2.10.2. Compressed Fixtures
        11. F.2.11. makemessages
          1. F.2.11.1. --all
          2. F.2.11.2. --extension
          3. F.2.11.3. --locale
          4. F.2.11.4. --domain
        12. F.2.12. reset <appname appname ...>
          1. F.2.12.1. --noinput
        13. F.2.13. runfcgi [options]
        14. F.2.14. runserver
          1. F.2.14.1. Examples of Using Different Ports and Addresses
          2. F.2.14.2. Serving Static Files with the Development Server
        15. F.2.15. shell
        16. F.2.16. sql <appname appname ...>
        17. F.2.17. sqlall <appname appname ...>
        18. F.2.18. sqlclear <appname appname ...>
        19. F.2.19. sqlcustom <appname appname ...>
        20. F.2.20. sqlflush
        21. F.2.21. sqlindexes <appname appname ...>
        22. F.2.22. sqlreset <appname appname ...>
        23. F.2.23. sqlsequencereset <appname appname ...>
        24. F.2.24. startapp <appname>
        25. F.2.25. startproject <projectname>
        26. F.2.26. syncdb
          1. F.2.26.1. --noinput
        27. F.2.27. test
          1. F.2.27.1. --noinput
        28. F.2.28. testserver <fixture fixture ...>
        29. F.2.29. validate
      3. F.3. Default Options
        1. F.3.1. --pythonpath
        2. F.3.2. --settings
        3. F.3.3. --traceback
        4. F.3.4. --verbosity
      4. F.4. Extra Niceties
        1. F.4.1. Syntax Coloring
        2. F.4.2. Bash Completion
    7. G. Request and Response Objects
      1. G.1. HttpRequest
        1. G.1.1. QueryDict Objects
        2. G.1.2. A Complete Example
      2. G.2. HttpResponse
        1. G.2.1. Construction HttpResponses
        2. G.2.2. Setting Headers
        3. G.2.3. HttpResponse Subclasses
        4. G.2.4. Returning Errors
        5. G.2.5. Customizing the 404 (Not Found) View
        6. G.2.6. Customizing the 500 (Server Error) View

Product information

  • Title: The Definitive Guide to Django: Web Development Done Right, Second Edition
  • Author(s):
  • Release date: July 2009
  • Publisher(s): Apress
  • ISBN: 9781430219361