Sams Teach Yourself Django in 24 Hours

Book description

In just 24 lessons of one hour or less, you will be able to build full-featured production websites using Django, the powerful web development framework based on Python.

Designed for experienced website developers who have at least some familiarity with the Python programming language, this book uses a straightforward, step-by-step approach. Each lesson builds on the previous ones, enabling you to learn the essentials of implementing the Django framework on a website from the ground up.

Step-by-step instructions carefully walk you through the most common Django tasks.

Q&As, quizzes, and exercises at the end of each lesson help you test your knowledge.

Notes and tips point out shortcuts and solutions.

Learn how to…

  • Install and configure the Django web development framework

  • Cleanly separate data, logic, and view layers

  • Implement site interfaces with build templates and views

  • Utilize templates and views to store, access, and retrieve data

  • Use the Django forms library

  • Define custom tags and filters to minimize coding

  • Secure sites with registration, authorization, logins, and permissions

  • Manage sessions and cookies

  • Implement middleware for request and response handling

  • Create sitemaps to inform search engines of your content

  • Internationalize your site

  • Optimize performance with caching

  • Deploy Django in multiple configurations

  • Maintain sites with Django’s administrator interface

  • Introduction 1

    Part I:  Creating the Website Framework

    Hour 1: Understanding Django 7

    Hour 2: Creating Your First Website 19

    Hour 3: Adding Models and Objects to Your Website 37

    Hour 4: Creating the Initial Views 63

    Part II: Implementing the Website Interface

    Hour 5: Using Data from the Database in Views 81

    Hour 6: Configuring Web Page Views 103

    Hour 7: Implementing Django Templates to Create Custom Views 117

    Hour 8: Using Built-in Template Tags to Enhance Views 139

    Hour 9: Using Built-in Template Filters to Enhance Views 155

    Hour 10: Adding Forms to Views 185

    Hour 11: Using Views to Add and Update Data in the Database 209

    Hour 12: Utilizing Generic Views 231

    Hour 13: Advanced View Configurations 269

    Part III: Implementing a Full-Featured Website

    Hour 14: Managing Site Users 295

    Hour 15: Adding Website Security 313

    Hour 16: Managing Sessions and Cookies 333

    Hour 17: Customizing Models in the Admin Interface 347

    Hour 18: Customizing the Admin Interface 365

    Part IV:  Implementing Advanced Website Components

    Hour 19: Implementing Middleware 383

    Hour 20: Internationalization and Localization 407

    Hour 21: Creating Sitemaps 423

    Hour 22: Implementing Multiple Websites 437

    Hour 23: Configuring Caching 451

    Hour 24: Deploying Django 465

    Appendixes

    Appendix A: Django Resources 477

    Appendix B: Django Form Field Objects 481

    Appendix C: Formatting Dates and Times 491

    Index 493

    Table of contents

    1. Table of Contents (1/3)
    2. Table of Contents (2/3)
    3. Table of Contents (3/3)
    4. Introduction
      1. Who Should Read This Book
      2. How This Book Is Organized
      3. How to Use This Book
    5. Part I: Creating the Website Framework
      1. HOUR 1: Understanding Django
        1. What Is Django?
        2. Why Use Django?
        3. Understanding Models
        4. Understanding Views
        5. Understanding Templates
        6. Configuring the settings.py File
        7. Using the manage.py Utility
        8. Understanding the Django Development Server
        9. Understanding the Admin Interface
        10. Installing Django
        11. Summary
        12. Q&A
        13. Workshop
        14. Exercises
      2. HOUR 2: Creating Your First Website
        1. Creating a Django Project
        2. Starting the Development Server
        3. Configuring the Database
        4. Installing an Application
        5. Adding Data Using the API
        6. Setting Up the URLConf File
        7. Creating a Simple View
        8. Summary
        9. Q&A
        10. Workshop
        11. Exercises
      3. HOUR 3: Adding Models and Objects to Your Website
        1. Installing the Admin Interface Model
        2. Updating the URLconf File to Allow Admin Access
        3. Activating the Model in the Admin Interface
        4. Adding, Modifying, and Viewing Objects in the Admin Interface
        5. Defining Data Models (1/3)
        6. Defining Data Models (2/3)
        7. Defining Data Models (3/3)
        8. Summary
        9. Q&A
        10. Workshop
        11. Exercises
      4. HOUR 4: Creating the Initial Views
        1. Setting Up the URLconf File
        2. Understanding the HttpRequest and HttpResponse Classes
        3. Configuring the URL Patterns
        4. Adding URL-Based Arguments to the Views
        5. Summary
        6. Q&A
        7. Workshop
        8. Exercises
    6. Part II: Implementing the Website Interface
      1. HOUR 5: Using Data from the Database in Views
        1. Adding Data to the Database
        2. Accessing Data in the Database
        3. Modifying Data in the Database
        4. Performing Queries in the Database (1/2)
        5. Performing Queries in the Database (2/2)
        6. Adding Data in a Model to a View
        7. Summary
        8. Q&A
        9. Workshop
        10. Exercises
      2. HOUR 6: Configuring Web Page Views
        1. Passing Extra Options to a View
        2. Using View Prefixes
        3. Using Additional URLconf Files
        4. Calling the View Functions Directly
        5. Summary
        6. Q&A
        7. Workshop
        8. Exercises
      3. HOUR 7: Implementing Django Templates to Create Custom Views
        1. Configuring the Template Directory
        2. Creating a Template (1/2)
        3. Creating a Template (2/2)
        4. Rendering a Template as an HTTP Response
        5. Extending Templates
        6. Embedding Templates
        7. Summary
        8. Q&A
        9. Workshop
        10. Exercises
      4. HOUR 8: Using Built-in Template Tags to Enhance Views
        1. Implementing Loops
        2. Implementing if Logic
        3. Adding Links with the url Tag
        4. Reducing Code Using the with Tag
        5. Adding Cycle Logic to Tables
        6. Summary
        7. Q&A
        8. Workshop
        9. Exercises
      5. HOUR 9: Using Built-in Template Filters to Enhance Views
        1. Understanding Filters
        2. Formatting Text (1/2)
        3. Formatting Text (2/2)
        4. Manipulating Lists (1/2)
        5. Manipulating Lists (2/2)
        6. Sorting Dictionaries
        7. Formatting Dates (1/2)
        8. Formatting Dates (2/2)
        9. Summary
        10. Q&A
        11. Workshop
        12. Exercises
      6. HOUR 10: Adding Forms to Views
        1. Creating Form Instances
        2. Rendering Forms as HTML
        3. Rendering Forms from Models (1/2)
        4. Rendering Forms from Models (2/2)
        5. Customizing Forms
        6. Summary
        7. Q&A
        8. Workshop
        9. Exercises
      7. HOUR 11: Using Views to Add and Update Data in the Database
        1. Handling GET and POST Requests
        2. Validating Data from a POST Against the Model (1/2)
        3. Validating Data from a POST Against the Model (2/2)
        4. Updating Data in the Database
        5. Adding Data to the Database (1/2)
        6. Adding Data to the Database (2/2)
        7. Summary
        8. Q&A
        9. Workshop
        10. Exercises
      8. HOUR 12: Utilizing Generic Views
        1. Understanding Generic Views
        2. Using Simple Generic Views
        3. Displaying an Object List in a Generic View
        4. Displaying Object Details in a Generic View
        5. Displaying Date-Based Objects in a Generic View (1/2)
        6. Displaying Date-Based Objects in a Generic View (2/2)
        7. Using Generic Object-Creation Views
        8. Using Generic Object-Update Views
        9. Using Generic Object-Deletion Views
        10. Summary
        11. Q&A
        12. Workshop
        13. Exercises
      9. HOUR 13: Advanced View Configurations
        1. Loading Templates from Applications
        2. Extending the Template System
        3. Creating Custom Filters
        4. Creating Custom Tags (1/3)
        5. Creating Custom Tags (2/3)
        6. Creating Custom Tags (3/3)
        7. Understanding How to Use RequestContexts in Templates
        8. Summary
        9. Q&A
        10. Workshop
        11. Exercises
    7. Part III: Implementing a Full-Featured Website
      1. HOUR 14: Managing Site Users
        1. Adding Users
        2. Adding Groups
        3. Setting User Permissions
        4. Summary
        5. Q&A
        6. Workshop
        7. Exercises
      2. HOUR 15: Adding Website Security
        1. Implementing User Logins
        2. Adding Logout Functionality
        3. Verifying Authentication
        4. Verifying Permissions
        5. Limiting Access to Generic Views
        6. Summary
        7. Q&A
        8. Workshop
        9. Exercises
      3. HOUR 16: Managing Sessions and Cookies
        1. Understanding Django’s Session Framework
        2. Configuring the Session Manager
        3. Using Django’s Test Cookies
        4. Setting and Retrieving Session Data
        5. Setting and Retrieving Cookies
        6. Summary
        7. Q&A
        8. Workshop
        9. Exercises
      4. HOUR 17: Customizing Models in the Admin Interface
        1. Customizing the Model Change List
        2. Customizing the Model Form
        3. Viewing Multiple Models Inline
        4. Summary
        5. Q&A
        6. Workshop
        7. Exercises
      5. HOUR 18: Customizing the Admin Interface
        1. Overriding Admin Templates at the Site Level
        2. Creating Custom Admin Views
        3. Overriding the Admin Templates at the Application or Object Level
        4. Overriding Block Tags in a Custom Admin Template
        5. Overriding the Built-in Admin Views in the URLconf File
        6. Summary
        7. Q&A
        8. Workshop
        9. Exercises
    8. Part IV: Implementing Advanced Website Components
      1. HOUR 19: Implementing Middleware
        1. Installing Middleware
        2. Implementing Middleware Applications
        3. Implementing a Request Preprocessor
        4. Implementing a View Preprocessor
        5. Implementing a Response Postprocessor
        6. Implementing an Exception Postprocessor
        7. Django’s Built-in Middleware
        8. Summary
        9. Q&A
        10. Workshop
        11. Exercises
      2. HOUR 20: Internationalization and Localization
        1. Localizing Strings in Python
        2. Localizing Strings in Templates
        3. Creating Language Files
        4. Setting Language Preference
        5. Summary
        6. Q&A
        7. Workshop
        8. Exercises
      3. HOUR 21: Creating Sitemaps
        1. Creating a Sitemap
        2. Creating a Sitemap of Generic Views
        3. Creating a Sitemap Index
        4. Pinging Google
        5. Summary
        6. Q&A
        7. Workshop
        8. Exercises
      4. HOUR 22: Implementing Multiple Websites
        1. Implementing the sites Framework
        2. Using the CurrentSiteManager Class (1/2)
        3. Using the CurrentSiteManager Class (2/2)
        4. Summary
        5. Q&A
        6. Workshop
        7. Exercises
      5. HOUR 23: Configuring Caching
        1. Configuring Caching Backends
        2. Implementing a Per-Site Cache
        3. Implementing a Per-View Cache
        4. Implementing a Per-Object Cache
        5. Managing Upstream Caching
        6. Summary
        7. Q&A
        8. Workshop
        9. Exercises
      6. HOUR 24: Deploying Django
        1. Deploying Django to Apache with mod_python
        2. Other Deployment Configurations
        3. Optimizing Django Deployment
        4. Summary
        5. Q&A
        6. Workshop
        7. Exercises
    9. Appendixes
      1. APPENDIX A: Django Resources
      2. APPENDIX B: Django Form Field Objects
        1. Field Objects
        2. Widget Objects
        3. Form Field to Model Field Mapping
      3. APPENDIX C: Formatting Dates and Times
    10. Index
      1. A
      2. B
      3. C
      4. D
      5. E
      6. F
      7. G
      8. H
      9. I
      10. J–K–L
      11. M
      12. N
      13. O
      14. P
      15. Q–R
      16. S
      17. T
      18. U
      19. V
      20. W
      21. X–Y–Z

    Product information

    • Title: Sams Teach Yourself Django in 24 Hours
    • Author(s): Brad Dayley
    • Release date: February 2008
    • Publisher(s): Sams
    • ISBN: 9780768680331