Practical Django Projects, Second Edition

Book description

Build a Django content management system, blog, and social networking site with James Bennett as he introduces version 1.1 of the popular Django framework.

You'll work through the development of each project, implementing and running the applications while learning new features along the way.

Web frameworks are playing a major role in the creation of today's most compelling web applications, because they automate many of the tedious tasks, allowing developers to instead focus on providing users with creative and powerful features. Python developers have been particularly fortunate in this area, having been able to take advantage of Django, a very popular open-source web framework whose stated goal is to "make it easier to build better web applications more quickly with less code."

Practical Django Projects introduces this popular framework by way of a series of real-world projects. Readers follow along with the development of each project, implementing and running each application while learning new features along the way. This edition is updated for Django 1.1 and includes an all-new chapter covering practical development tools and techniques you'll be able to apply to your own development workflow.

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright
  4. Contents at a Glance
  5. Contents
  6. About the Author
  7. About the Technical Reviewer
  8. Introduction
  9. CHAPTER 1 Welcome to Django
    1. What's a Web Framework and Why Should I Want One?
    2. Saying Hello to Django
    3. Saying Hello to Python
    4. Installing Django
    5. Taking Your First Steps with Django
    6. Exploring Your Django Project
    7. Looking Ahead
  10. CHAPTER 2 Your First Django Site: A Simple CMS
    1. Configuring Your First Django Project
    2. Putting Together the CMS
    3. Introducing the Django Template System
    4. Looking Ahead
  11. CHAPTER 3 Customizing the Simple CMS
    1. Adding Rich-Text Editing
    2. Adding a Search System to the CMS
    3. Improving the Search View
    4. Improving the Search Function with Keywords
    5. Looking Ahead
  12. CHAPTER 4 A Django-Powered Weblog
    1. Compiling a Feature Checklist
    2. Writing a Django Application
      1. Projects vs. Applications
      2. Standalone and Coupled Applications
    3. Creating the Weblog Application
    4. Designing the Models
    5. Building the Entry Model
      1. Basic Fields
      2. Slugs, Useful Defaults, and Uniqueness Constraints
      3. Authors, Comments, and Featured Entries
      4. Different Types of Entries
      5. Categorizing and Tagging Entries
      6. Writing Entries Without Writing HTML
      7. Finishing Touches
    6. The Weblog Models So Far
    7. Writing the First Views
    8. Using Django's Generic Views
    9. Decoupling the URLs
    10. Looking Ahead
  13. CHAPTER 5 Expanding the Weblog
    1. Writing the Link Model
    2. Views for the Link Model
    3. Setting Up Views for Categories
    4. Using Generic Views (Again)
    5. Views for Tags
    6. Cleaning Up the URLConf Module
    7. Handling Live Entries
    8. Looking Ahead
  14. CHAPTER 6 Templates for the Weblog
    1. Dealing with Repetitive Elements: The Power of Inheritance
      1. How Template Inheritance Works
      2. Limits of Template Inheritance
    2. Defining the Base Template for the Blog
    3. Setting Up Section Templates
    4. Displaying Archives of Entries
      1. Entry Index
      2. Yearly Archive
      3. Monthly and Daily Archives
      4. Entry Detail
    5. Defining Templates for Other Types of Content
    6. Extending the Template System with Custom Tags
      1. How a Django Template Works
      2. A Simple Custom Tag
      3. Writing a More Flexible Tag with Arguments
      4. Writing the LatestContentNode
      5. Registering and Using the New Tag
    7. Looking Ahead
  15. CHAPTER 7 Finishing the Weblog
    1. Comments and django.contrib.comments
    2. Implementing Model Inheritance and Abstract Models
      1. Installing the Comments Application
      2. Performing Basic Setup
      3. Retrieving Lists of Comments for Display
    3. Moderating Comments
      1. Using Signals and the Django Dispatcher
      2. Building the Automatic Comment Moderator
      3. Adding Akismet Support
      4. Sending E-mail Notifications
      5. Using Django's Comment-Moderation Features
    4. Adding Feeds
      1. Creating the LatestEntriesFeed Class
      2. Generating Entries by Category: A More Complex Feed Example
    5. Looking Ahead
  16. CHAPTER 8 A Social Code-Sharing Site
    1. Compiling a Feature Checklist
    2. Setting Up the Application
    3. Building the Initial Models
      1. The Language Model
      2. The Snippet Model
    4. Testing the Application
    5. Building Initial Views for Snippets and Languages
      1. CSS for pygments Syntax Highlighting
      2. Views for Languages
      3. An Advanced View: Top Authors
      4. Improving the View of Top Authors
      5. Adding a top_languages View
    6. Looking Ahead
  17. CHAPTER 9 Form Processing in the Code-Sharing Application
    1. A Brief Tour of Django's Form System
      1. A Simple Example
      2. Validating the Username
      3. Validating the Password
      4. Creating the New User
      5. How Form Validation Works
      6. Processing the Form
    2. Writing a Form for Adding Code Snippets
      1. Writing a View to Process the Form
      2. Writing the Template to Handle the add_snippet View
    3. Automatically Generating the Form from a Model Definition
    4. Simplifying Templates That Display Forms
    5. Editing Snippets
    6. Looking Ahead
  18. CHAPTER 10 Finishing the Code-Sharing Application
    1. Bookmarking Snippets
    2. Adding Basic Bookmark Views
    3. Creating a New Template Tag: {% if_bookmarked %}
      1. Parsing Ahead in a Django Template
      2. Resolving Variables Inside a Template Node
    4. Using RequestContext to Automatically Populate Template Variables
    5. Adding the User Rating System
      1. Rating Snippets
      2. Adding an {% if_rated %} Template Tag
      3. Retrieving a User's Rating
    6. Looking Ahead
  19. CHAPTER 11 Practical Development Techniques
    1. Using Version-Control Systems to Track Your Code
      1. A Simple Example
      2. Version-Control Tools and Hosting Options
      3. Choosing and Using a VCS
    2. Using Isolated Python Environments to Manage Software
    3. Using Build Tools
    4. Using a Deployment Tool
    5. Simplifying Your Django Development Process
      1. Living Without Projects
      2. Using Relative Paths in Settings
      3. Dealing with Settings That Change for Different Environments
      4. Unit-Testing Your Applications
    6. Looking Ahead
  20. CHAPTER 12 Writing Reusable Django Applications
    1. One Thing at a Time
      1. Staying Focused
      2. Advantages of Tightly Focused Applications
    2. Developing Multiple Applications
      1. Drawing the Lines Between Applications
      2. Splitting Up the Code-Sharing Application
    3. Building for Flexibility
      1. Flexible Form Handling
      2. Flexible Template Handling
      3. Flexible Post-Form Processing
      4. Flexible URL Handling
      5. Taking Advantage of Django's APIs
      6. Staying Generic
    4. Distributing Django Applications
      1. Python Packaging Tools
      2. Writing a Script with distutils
      3. Standard Files to Include in a Package
      4. Documenting an Application
    5. Looking Ahead
  21. Index

Product information

  • Title: Practical Django Projects, Second Edition
  • Author(s): James Bennett
  • Release date: June 2009
  • Publisher(s): Apress
  • ISBN: 9781430219385