The Definitive Guide to Pylons

Includes SQLAlchemy, JavaScript, and WSGI

James Gardner

Publisher: Apress, 2009, 536 pages

ISBN: 1-59059-934-9

Keywords: Python, Web Programming

Last modified: May 4, 2019, 10:49 p.m.

Spurred by the enormous popularity of Ruby on Rails, web frameworks have revolutionized the way developers of all programming languages tackle the often complex task of web application development. Some of the most exciting activity in this area can be seen in the Python community, one of the wildly popular frameworks to enter the fray being Pylons.

Cofounder and lead developer James Gardner brings you a comprehensive introduction to Pylons, the web framework that uses the best of Ruby, Python, and Perl and the emerging WSGI standard to provide structure and flexibility. With expert guidance from the author, you’ll learn how to create your own Pylons–driven web site using SQLAlchemy and FormEncode and attain the mastery of advanced Pylons features, such as internationalization and localization, packaging and deployment.

What you’ll learn

  • Install and configure Pylons, and create your first Pylons–driven web application.
  • Take advantage of Pylons’ built–in support for advanced features such as session management, web services, and Ajax.
  • Develop your web applications in the most efficient way possible through test–driven development, logging, testing.
  • Wield the true power of Pylons through its extension capabilities, unique support for WSGI, and the ability to integrate with other popular frameworks such as Django.
  • Part 1: Getting Started
    • Chapter 1: Introducing Pylons
      • The Old Way: CGI Scripts
      • The Pylons Way
        • Model View Controller Architecture
        • Convention Over Configuration
        • Loose Coupling and Clean Separation
        • Other Features
      • The Python Language
        • Python 3.0
      • The Pylons Community
      • Pylons Components
      • What’s Coming Up
      • Summary
    • Chapter 2: Installing Pylons
      • Quick Start to Installation for the Impatient
      • Installation in Detail
        • Using the Python Package Index
        • Setting Up a Virtual Python Environment
        • Working with Easy Install
        • Installing Pylons
        • Understanding Eggs
      • Advanced Topics
        • Activating and Deactivating a Virtual Python Environment
        • Setting Virtualenv Options
        • Choosing Package Versions with Easy Install
        • Installing with a Proxy Server
        • Troubleshooting Easy Install
        • Working on the Bleeding Edge
      • Platform-Specific Notes
        • Linux and BSD
        • Mac OS X
        • Windows
      • Summary
    • Chapter 3: Exploring Pylons
      • Exploring Pylons’ Dependencies
      • Creating a Pylons Project
      • Serving a Pylons Application
        • Configuration Files
        • The Paste HTTP Server
        • Static Files
        • A Word About IP Addresses, Hosts, and Security
      • Exploring a Pylons Project’s Directory Structure
      • Creating a Controller and Modifying the Routes
      • Understanding How HTTP Works
      • Exploring the Environment
      • Understanding the Pylons Request and Response
      • Request
      • Response
      • Understanding Pylons Globals
        • Helpers
        • Context Object
        • App Globals Object
      • Configuring Pylons
      • Controller Imports
      • Summary
    • Chapter 4: Tracking Down and Handling Problems
      • Using the Pylons Interactive Debugger
        • Production Use
        • E-mail Options
      • Summary
    • Chapter 5: Using View Templates
      • Introducing Mako
        • Using the Template Context c Global
        • Basic Template Syntax
        • Default Pylons Template Variables
        • Mako Runtime Built-Ins
        • Separation of Logic and View
      • Security Considerations and WebHelpers
        • Writing Your Own Helpers
        • Applying Filters in Templates
      • Structuring Template Code
        • Using <%def> Blocks
        • The Mako Cache
        • Capturing Output
        • Namespaces
        • The body() Def
      • Template Inheritance Chains
        • Simple Inheritance
        • Next Namespace
        • Parent Namespace
      • Behind the Scenes
        • Caching
        • Alternative Template Languages
        • Multiple Template Languages
        • Working with Your Own Templating Language
      • Summary
    • Chapter 6: Working with Forms and Validators
      • The Basics
        • POST vs. GET
        • The Resubmitted Data Problem
      • Building Forms with Helpers
      • Uploading Files
      • Handling Forms Manually
      • Introducing FormEncode
        • Configuring Validators
      • Using HTML Fill
        • Error Message Formatting
        • Render Arguments
      • Doing Validation the Quick Way
      • Using Custom Validators
      • Solving the Repeating Fields Problem
        • Creating the Form
      • Summary
    • Chapter 7: Introducing the Model and SQLAlchemy
      • Storing Data in the Filesystem
      • Storing Data in Amazon S3
      • Exploring Database Approaches
        • Object Databases
        • XML Databases
        • Relational Database Management Systems
        • Object-Relational Mappers
      • Setting Up SQLAlchemy
        • Installing the DB-API Driver
        • Installing SQLAlchemy
        • Creating a Database
      • Exploring SQLAlchemy’s Architecture
        • Engine API
        • Metadata and Type APIs
        • SQL Expression API
      • Exploring the Object-Relational API
        • Object-Relational Principles
        • More Metadata
        • Classes and Mappers
        • Understanding the Session
        • Exploring the Session
        • Queries
        • Working with Objects
        • Declarative API
      • Maintaining Performance
      • Summary
    • Chapter 8: Starting the SimpleSite Tutorial
      • Getting Started with SimpleSite
      • Exploring the Template Structure
      • Using SQLAlchemy in Pylons
        • Configuring the Engine
        • Creating the Model
        • Creating the Database Tables
        • Querying Data
        • Understanding the Role of the Base Controller
        • Using a SQLAlchemy Session in Pylons
      • Updating the Controller to Support Editing Pages
        • view()
        • new()
        • create()
        • edit() and save()
        • list()
        • delete()
      • Updating the Footer
      • Using Pagination
      • Formatting Dates and Times
      • Using Sessions and a Flash Message
      • Summary
  • Part 2: Advanced Pylons
    • Chapter 9: URLs, Routing and Dispatch
      • Pylons Routing in Detail
        • Pylons Dispatch
      • Routes in Detail
        • Route Parts
        • Default Variables
      • Generating URLs
        • Named Routes
        • Static Named Routes
        • Internal Static Routes
      • Choosing Good URLs
      • Unnecessary Routes Features
        • Route Minimization
        • Route Memory
        • Implicit Defaults
        • Best Practice
      • Advanced URL Routing
        • Requirements
        • Conditions
        • Filter Functions
      • Summary
    • Chapter 10: Unicode
      • A Brief History
      • Introducing Unicode
      • Unicode in Python 2
        • Unicode Literals
        • Handling Errors
        • Decoding Unicode
        • Encoding Unicode
        • Python Source Code Encoding
        • Unicode and Files
      • Unicode Considerations in Pylons Programming
        • Request Parameters
        • Templating
        • Output Encoding
        • Databases
        • A Complete Request Cycle
      • Summary
    • Chapter 11: Internationalization and Localization
      • Understanding the Process
        • Marking Strings for Internationalization
        • Extracting Messages and Handling Translations
      • Seeing It in Action
        • Using Babel
        • Supporting Multiple Languages
        • Updating the Catalog
        • Translations Within Templates
        • Babel Extractors
        • Setting the Language in the Config File
        • Using a Session to Store the User’s Language
      • Advanced Internationalization Techniques
        • Fallback Languages
        • Lazy Translations
        • Plural Forms
        • Search Engine Considerations
      • Summary
    • Chapter 12: Testing
      • Types of Testing and the Development Process
      • Unit Testing with nose
        • Introducing nose
        • Search Locations
      • Functional Testing
        • How Does the Test Setup Work?
        • Testing the save() Action
        • Testing Your Own Objects
      • Interactive Shell
      • Summary
    • Chapter 13: Documentation
      • Python’s Documentation Tools
        • Comments
        • Docstrings
        • The Built-In help() Function
      • Doctests
      • Introducing reStructuredText
      • Introducing Sphinx
        • Using Sphinx
        • Documenting Python Source Code
        • Automatically Generating Documentation
        • Syntax Highlighting
      • Summary
    • Chapter 14: SimpleSite Tutorial Part 2
      • Comments System: One-to-Many Mappings
        • Planning the Controller
        • Modifying the Routes
        • Creating the Controller
        • Updating the Controller to Handle Comments
        • Setting the Page ID Automatically
      • Updating the Page View
        • Handling Deleted Pages
      • Tags: Many-to-Many Mappings
        • Creating the tag Controller
        • Constraining Tag Names
      • Adding Tags to Pages
        • Deleting Tags and Pages
      • Creating a Navigation Hierarchy
        • Using Inheritance in SQLAlchemy
        • Setting Up Initial Data
        • Creating the Controllers
        • The Page Controller
      • Changing the Routing
      • Adding the Navigation Elements
      • Adding Some Style
      • Summary
    • Chapter 15: CSS, JavaScript, and Ajax
      • Adding YUI to Your Project
      • Resetting the Browser CSS
      • Fonts
      • Grids
        • Template Preset Grids
        • Nested Grids
        • Special Nested Grids
      • Updating SimpleSite to Use CSS Grids
      • Introducing Firebug
      • Introducing JavaScript
      • JavaScript Essentials
        • Operators of Interest
        • Types
        • Functions
        • Function Scope and Closures
        • Objects
        • this
        • Namespaces
        • Inheritance
        • Prototypes
        • JavaScript in HTML
      • The Document Object Model
        • Navigating the DOM
        • Manipulating the DOM
      • The Event Model
        • Same Origin Policy
        • Browser Detection vs. Feature Detection
      • Adding Animation to the SimpleSite Flash Message
      • Ajax
        • Debugging Ajax Requests
        • JSON
      • Reducing Page Load Time
      • Summary
  • Part 3: Expert Pylons
    • Chapter 16: The Web Server Gateway Interface (WSGI)
      • Introducing WSGI
        • WSGI Applications
        • Using Instances of Classes
        • WSGI in Pylons Controllers
        • WSGI Servers
        • WSGI Middleware
      • Writing WSGI Middleware
        • Modifying the Environment
        • Changing the Status and Headers
        • Handling Errors
        • Altering the Response
      • Testing the Gzip Middleware
      • Summary
    • Chapter 17: Pylons’ Internal Architecture
      • A Bit of History
      • Egg Entry Points
        • Entry Points and websetup.py
      • The Pylons Config File
        • Default Config Options
        • Constructing a Server
        • Constructing an Application
        • Composite Applications
        • Pipelines and Filters
        • Understanding Factories
        • Alternative Ways of Specifying Factories
        • Configuration Inheritance
      • Accessing the Pylons WSGI Application and Other Objects Programmatically
        • Accessing the Server, Application, and Filters
        • Accessing Configuration Options
        • Creating a Pylons Application with Paste Deploy
      • The Pylons Middleware Stack
        • Application State vs. Request State
      • Creating an Application
        • Loading the Pylons Environment
        • The PylonsApp Instance
        • The Middleware Chain
      • Handling a Request
        • The Cascade
        • The Registry Manager, StackedObjectProxy, and Pylons Globals
        • Returning to the Middleware Chain
        • The Role of PylonsApp
        • The Role of WSGIController
      • Handling the Response
        • abort(), redirect_to(), and HTTPException
        • Exception Handling
        • Error Documents
        • Streaming Content
        • Returning Unicode from an Action
      • Summary
    • Chapter 18: Authentication and Authorization
      • Private Data
      • A Homegrown Solution
      • AuthKit
      • Authentication Middleware
      • Authorization and Permissions
        • The Authorization Decorator
        • The Authorization Middleware
        • The Authorization Function
        • Protecting a Controller
      • Groups, Roles, and Permissions
      • User Management API
      • Cookie Options
      • Alternative Methods
      • Functional Testing
      • General Security Considerations
        • Secure Sockets Layer
        • Encrypted Passwords
      • Summary
    • Chapter 19: SimpleSite Tutorial Part 3
      • Authentication and Authorization
        • Setting Up the Middleware
        • Adjusting websetup.py
        • Protecting Controller Actions
        • Changing Templates Based on Permissions
        • Signing In and Signing Out
        • Styling the Sign-in Screen
        • Protecting the Rest of the Actions
        • Using the AuthKit User Management API
      • Error Documents
        • Customizing the Error Documents for SimpleSite
      • Adding a WYSIWYG Interface
      • Configuring the setup.py File
        • Choosing a Version Number
        • Configuring Dependencies
        • Extra Dependencies
        • Extra Dependency Links
        • Specifying Metadata
        • Customizing the Long Description
        • Customizing the Production Config File Template
      • Packaging a Pylons Project for Distribution
        • Building an Egg File
        • Publishing an Egg on the Python Package Index
      • Making SimpleSite into a Paste Project Template
        • Introducing Project Template Variables
        • Using Project Template Variables
        • Completing the Cycle
      • Summary
    • Chapter 20: Logging
      • Getting Started with Pylons Logging
      • Understanding the logging Module
        • Understanding Log Levels
        • Logging Variables
        • Logging in Templates
      • Introducing Logging Configuration
        • Logger Sections
        • Handler Sections
        • Formatter Sections
      • Redirecting Log Output Using Handlers
        • Logging to a File
        • Logging to wsgi.errors
        • Configuring Which Messages Are Logged
      • Controlling Propagation with Loggers
        • Using Propagation to Filter Messages
        • Summarizing Propagation Options
      • Capturing Log Output from Other Software
        • Capturing SQLAlchemy Log Messages Using Propagation
        • Capturing AuthKit Messages Using a Handler
      • Production Configuration
      • Summary
    • Chapter 21: Deployment
      • Choosing or Setting Up a Python Environment
        • Using the System Python Environment
        • Platform Packages or Easy Install?
        • Using Buildout
        • Setting Up a Virtual Python Environment
        • Dealing with Activate
      • Installing the Required Software into the Environment
      • Creating a Config File for the Application
      • Setting Up the Application Instance
      • Serving the Application from the Installed Environment
      • Deployment Options
        • Embedding
        • Proxying
      • Using Apache to Proxy Requests to Pylons
        • Setting Up Log Files
        • Creating init Scripts
        • Restarting Stopped Applications
      • Embedding Pylons in Apache with mod_wsgi
        • Setting Up a Virtual Host
        • Troubleshooting
      • Deployment on Windows
      • Summary
  • Appendix: Licenses

Reviews

The Definitive Guide to Pylons

Reviewed by Roland Buresund

Very Good ******** (8 out of 10)

Last modified: Aug. 15, 2009, 1:44 a.m.

This is truly the best book about any Web-framework I have ever read. It covers the ground of the framework itself, its pholosophy, as well as best practices (both for the framework and development in general) in an excellent way.

I want more like this, and we should have a much nicer environment out there.

Recommended.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required