Lightweight Django

Book description

How can you take advantage of the Django framework to integrate complex client-side interactions and real-time features into your web applications? Through a series of rapid application development projects, this hands-on book shows experienced Django developers how to include REST APIs, WebSockets, and client-side MVC frameworks such as Backbone.js into new or existing projects.

Learn how to make the most of Django’s decoupled design by choosing the components you need to build the lightweight applications you want. Once you finish this book, you’ll know how to build single-page applications that respond to interactions in real time. If you’re familiar with Python and JavaScript, you’re good to go.

  • Learn a lightweight approach for starting a new Django project
  • Break reusable applications into smaller services that communicate with one another
  • Create a static, rapid prototyping site as a scaffold for websites and applications
  • Build a REST API with django-rest-framework
  • Learn how to use Django with the Backbone.js MVC framework
  • Create a single-page web application on top of your REST API
  • Integrate real-time features with WebSockets and the Tornado networking library
  • Use the book’s code-driven examples in your own projects

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Why This Book?
    2. Who Should Read This Book?
    3. Who Should Not Read This Book?
    4. About the Examples
    5. Organization of This Book
    6. Conventions Used in This Book
    7. How to Contact Us
    8. Acknowledgments
      1. Julia
      2. Mark
  2. Prerequisites
    1. Python
      1. Python Packages
    2. Web Development
      1. JavaScript
      2. Browser Support
    3. Additional Software
  3. 1. The World’s Smallest Django Project
    1. Hello Django
      1. Creating the View
      2. The URL Patterns
      3. The Settings
      4. Running the Example
    2. Improvements
      1. WSGI Application
      2. Additional Configuration
      3. Reusable Template
  4. 2. Stateless Web Application
    1. Why Stateless?
    2. Reusable Apps Versus Composable Services
    3. Placeholder Image Server
      1. Views
      2. URL Patterns
    4. Placeholder View
      1. Image Manipulation
      2. Adding Caching
    5. Creating the Home Page View
      1. Adding Static and Template Settings
      2. Home Page Template and CSS
      3. Completed Project
  5. 3. Building a Static Site Generator
    1. Creating Static Sites with Django
    2. What Is Rapid Prototyping?
    3. Initial Project Layout
      1. File/Folder Scaffolding
      2. Basic Settings
    4. Page Rendering
      1. Creating Our Base Templates
      2. Static Page Generator
      3. Basic Styling
      4. Prototype Layouts and Navigation
    5. Generating Static Content
      1. Settings Configuration
      2. Custom Management Command
      3. Building a Single Page
    6. Serving and Compressing Static Files
      1. Hashing Our CSS and JavaScript Files
      2. Compressing Our Static Files
    7. Generating Dynamic Content
      1. Updating Our Templates
      2. Adding Metadata
  6. 4. Building a REST API
    1. Django and REST
    2. Scrum Board Data Map
      1. Initial Project Layout
      2. Project Settings
      3. No Django Admin?
      4. Models
    3. Designing the API
      1. Sprint Endpoints
      2. Task and User Endpoints
      3. Connecting to the Router
      4. Linking Resources
    4. Testing Out the API
      1. Using the Browsable API
      2. Adding Filtering
      3. Adding Validations
      4. Using a Python Client
    5. Next Steps
  7. 5. Client-Side Django with Backbone.js
    1. Brief Overview of Backbone
    2. Setting Up Your Project Files
      1. JavaScript Dependencies
      2. Organization of Your Backbone Application Files
    3. Connecting Backbone to Django
    4. Client-Side Backbone Routing
      1. Creating a Basic Home Page View
      2. Setting Up a Minimal Router
      3. Using _.template from Underscore.js
    5. Building User Authentication
      1. Creating a Session Model
      2. Creating a Login View
      3. Generic Form View
      4. Authenticating Routes
      5. Creating a Header View
  8. 6. Single-Page Web Application
    1. What Are Single-Page Web Applications?
    2. Discovering the API
      1. Fetching the API
      2. Model Customizations
      3. Collection Customizations
    3. Building Our Home Page
      1. Displaying the Current Sprints
      2. Creating New Sprints
    4. Sprint Detail Page
      1. Rendering the Sprint
      2. Routing the Sprint Detail
      3. Using the Client State
      4. Rendering the Tasks
      5. AddTaskView
    5. CRUD Tasks
      1. Rendering Tasks Within a Sprint
      2. Updating Tasks
      3. Inline Edit Features
  9. 7. Real-Time Django
    1. HTML5 Real-Time APIs
      1. Websockets
      2. Server-Sent Events
      3. WebRTC
    2. Websockets with Tornado
      1. Introduction to Tornado
      2. Message Subscriptions
    3. Client Communication
      1. Minimal Example
      2. Socket Wrapper
      3. Client Connection
      4. Sending Events from the Client
      5. Handling Events from the Client
      6. Updating Task State
  10. 8. Communication Between Django and Tornado
    1. Receiving Updates in Tornado
      1. Sending Updates from Django
      2. Handling Updates on the Client
    2. Server Improvements
      1. Robust Subscriptions
      2. Websocket Authentication
      3. Better Updates
      4. Secure Updates
    3. Final Websocket Server
  11. Index
  12. Colophon
  13. Copyright

Product information

  • Title: Lightweight Django
  • Author(s): Julia Solórzano, Mark Lavin
  • Release date: November 2014
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491945940