### Navigation

- index
- modules |
- next |
- previous |
- TurboGears 2.1.5 documentation »
- Search:
- Extended Table of Contents »

# Tips and Recipes

This page collects documentation which describes how to work with TurboGears to accomplish an effect. Normally you should have completed a few Advanced Tutorials so that you have a feel for the general workflow within TurboGears before you dive into these documents.

## Core: Read These Pages!

These pages are the most useful pages for a new TurboGears developer to read after going through the tutorials. Reading the material here will help make you a more productive developer with TurboGears.

We cannot stress this enough: Read These Pages!

- Authentication and Authorization in TurboGears 2
- FormEncode @validate, and TurboGears Validation
- Writing Controller Methods
- Genshi How-To
- ToscaWidgets
- TurboGears 2 Configuration
- Configuring and using the Logging System
- Serving Static Files (Css, Javascript, Images, etc.)
- Handling Internationalization And Localization

Todo

link repoze.who, repoze.what, and the other key middleware

### Modeling Your Application

SQLAlchemy is the default data-storage layer for TurboGears 2.1.5. Ming is supported as the alternative storage layer for MongoDB. The SQLAlchemy-migrate project is the officially supported mechanism for updating and migrating your database.

- Working With SQLAlchemy And Your Data Model
- SQLAlchemy and Transaction Config Settings
- Database Schema Migrations
- Working With Ming And MongoDB

Todo

Document initial DB setup in websetup.py

Todo

Link DB setup (MySQL, PostgreSQL, etceteras) docs

Todo

document the transaction module, part of the repoze.tm package, introduction for implementers here... http://repoze.org/tmdemo.html

### Handling HTTP Requests (Controllers)

- Writing Controller Methods
- Web Session Usage
- FormEncode @validate, and TurboGears Validation
- TurboGears Form Handling Overview
- ToscaWidgets
- Using ToscaWidgets to Create Forms
- Pagination Quickstart For Turbogears2
- Authentication and Authorization in TurboGears 2
- Adding OpenID Support
- `webob` – WebOb
- `tg.flash` – Flash
- `tg.decorators` – Decorators
- Content Types and Request Extensions
- A Request’s Flow Through The TurboGears Stack
- Caching
- Routes Integration in TG2
- Generating RSS and Atom Feeds

Todo

Document “community” sites; user-signup mechanisms (e.g. tgext.registration2), OpenID, Recaptcha, etceteras as sub-section

### Automatic Forms/Controllers

The TurboGears Admin system is built on top of the Sprox and tgext.crud system. You can use the same automatically generated forms and controllers to help you quickly prototype your applications. The Movie Tutorial introduces this usage of Sprox.

- Developing RESTful Web Applications with TurboGears
- `tgext.crud.controller`
- TurboGears Administration System

### Templates/Views

By default your TurboGears 2.1.5 project will be configured to use the Genshi templating language. TurboGears allows for the use of alternate templating languages.

Note: most new users do not need to choose an alternate templating language.

- Genshi How-To
- Full Description of master.html
- Templating Options
- Why Chameleon Genshi?
- Why Mako?
- Why Jinja?
- Adding Captcha To Your Form

### Javascript Libraries

Modern web-sites are dynamic, flexible, Javascript-code-heavy pieces of software. You will almost certainly want to use one of the major Javascript libraries to make the process of creating your sites less painful. The ToscaWidgets package provides plug-ins for each of the three major libraries, JQuery, Dojo and Ext, as well as the older Mochikit package which was the default in TurboGears 1.x.

- Adding a JavaScript Library Include to Every Page
- ToscaWidgets Cookbook
- JQuery FlexiGrid Widget
- JQuery Flot Widget
- JQuery TreeView Widget Tutorial
- JQuery AjaxForm Widget
- Adding JSON with MochiKit to the `wiki20`
- Serving Static Files (Css, Javascript, Images, etc.)

Todo

JQuery, Dojo, EXT usage doc-links

Todo

Link documentation for doing JSON RPC/Ajax here

## Testing

- Testing TurboGears Applications
  - Why is writing tests so essential?
  - Unit testing with “Nose”
  - Testing your model classes
  - Testing your controllers
  - Measuring code coverage
  - Want to learn more?

## Installation and Deployment

- TurboGears 2.1.5 Standard Installation
  - Recommended Installation Environment
  - System Package Installation
  - Installation for the Impatient
  - Explaining the Installation Process
  - Running the Installed Environment
  - Upgrading TurboGears
  - Install a Database Driver
  - What’s Next?
- Alternate Installation Process
  - 32-bit Windows
  - Mac OSX Install
  - Linux Root Install
  - Python 2.4 Installation
  - Install Via PIP
  - Source Install (Development Version)
- Deployment
  - Standard Deployment Pattern
  - Apache Web Server
  - Apache Mod-WSGI
  - Production Database
  - Production Config
  - Deploying Your Project Code
  - Deploying your TG application with an Egg and Easy Install
  - Optimizing Toscawidgets Resources
  - Alternate Deployment Patterns
  - Deploy with a Source Code Checkout
  - Deploying as a Service/Daemon
  - Running TurboGears 2.1.5 behind Apache with Mod Proxy
  - FastCGI/WSGI – Running TurboGears 2.1.5 behind Apache
  - Lighttpd and FastCGI
  - NGINX Web Server

Todo

Difficulty Medium: document how to “freeze” applications (PIP, zc.buildout, etceteras) for re-deployment with precisely the same software on each machine (no downloads etceteras)

Todo

document use of Nginx beyond just saying you can do it

Todo

(maybe) document use of Twisted WSGI wrapper?

## Tools

- Profiling Your App
- ToolBox
- Command Line Reference
- TurboGears 2 Configuration
- Configuring and using the Logging System
- Command Line Scripts
- Scheduling Tasks

## Special Effects and Extensions

- Using Multiple Databases In TurboGears
- Using PyAMF With TurboGears2
- Using FirePython With TurboGears2
- Using Authorize.net in a TurboGears Form
- tgext.geo: Geographic Extensions for TurboGears

Todo

Document use of Ming and MongoDB with TurboGears

### Real-time Web

- Real-time TurboGears Introduction
- Moksha

## Performance and optimization

- Profiling Your App
- Template Performance
- Caching

Todo

Difficulty: Medium. optimization tips for SQLAlchemy usage

Todo

Difficulty: Easy. Validate that toctree maxdepth values are appropriate

Todo

Difficulty: Easy. Explain usage of tgscheduler and how to use SQLAlchemy in a task

### Next Steps

- The Gears in Detail – learn how TurboGears 2.1.5 works, changes since the 1.x release, and how to contribute to the project