TurboGears Upgrade Guide

To upgrade to the latest released version of TurboGears, you should first upgrade setuptools and then upgrade TurboGears. To do so, download the ez_setup.py script. On Windows:

ez_setup.py -U setuptools

easy_install -Uf http://www.turbogears.org/download/index.html TurboGears

On Mac OS X and other *nix-like systems:

sudo python ez_setup.py --script-dir /usr/local/bin -U setuptools

sudo easy_install -Uf http://www.turbogears.org/download/index.html --script-dir /usr/local/bin TurboGears

Please also be aware of backwards compatibility issues. These are addressed in the remainder of the guide.

Updating from 0.9x to 0.9a5

Identity has changed to use PEP 8 (Python standard coding convention) style names. SQL migration scripts are available to help convert your database to the new names.

Additionally, your identity login screen must have a button that is named "login" or another name specified in the identity.form.submit configuration variable.

Updating from 0.9a1 to 0.9a2

TurboGears 0.9 introduced a new config file format that allowed you to do basically anything that can be done in Python. The modules looked mostly like INI files, but were actually Python modules being executed in a slightly altered namespace.

It turns out that this had issues with Python 2.3, and some other minor issues that arose because these files ended in .py, but were not truly importable Python modules.

For these reasons, TurboGears has switched back to the original CherryPy-style config file in 0.9a2. The configuration change that persists between TurboGears 0.8 and 0.9 is that configuration is now split between two files: a deployment config file (dev.cfg, prod.cfg) and a package config file: yourpackagename/config.cfg.

There are a few minor, manual steps required to shift to the old/new config format if you were using 0.9 prior to 0.9a2:

  1. Rename "devcfg.py" to "dev.cfg"
  2. Rename "prodcfg.py" to "prod.cfg"
  3. mkdir "yourpackage/config"
  4. Create an empty file called in "yourpackage/config" called __init__.py (to make yourpackage/config a proper Python package).
  5. Rename "yourpackage/config.py" to "yourpackage/config/app.cfg"
  6. Edit your start-[yourproject].py file
    1. Change the references to devcfg.py to dev.cfg
    2. Change the references to prodcfg.py to prod.cfg
    3. Change the references to yourpackage.config to yourpackage.config.app
  7. Edit dev.cfg and prod.cfg to add [global] at the top of the file
  8. Edit yourpackage/config/app.cfg:
    1. Add [global] at the top of the file
    2. Change any path("something") to [something] (note the removal of quotes)
    3. Change calls to absfile to use %(top_level_dir)s. This diff will give you an idea of the change:
      -static_filter.dir = absfile("${package}", "static")
      +static_filter.dir = "%(top_level_dir)s/static"
                      

Updating from 0.8 to 0.9

There are a number of changes that will need to be made to your project in order to upgrade to TurboGears 0.9.

Upgrade Project Files and Configuration Files

One of the big changes in 0.9 is how configuration files work. Configuration files are now python modules, which provide a great deal of flexibility. The old configuration files will still work, but all ongoing development is going to be in the new format, and migration is relatively painless. The easiest way to add the new configuration files is to run the following command (in the base directory of your project):

tg-admin update

Running this command is going to try and upgrade (and overwrite!) existing files, so be careful! tg-admin will prompt you with 'Y/n/d/b' before overwriting anything. Y is yes (overwrite), n is no (don't overwrite), d will show you a diff of the new and old file, and b will make a backup of your existing file before overwriting. Briefly, files that are going to be updated are:

A new config file will be placed in yourpackage/config/app.cfg. Configuration items that are applicable to both development and production now go into app.cfg. The reason for this is that it allows your project to be conveniently packaged as an egg if you choose to do so, with the project specific configuration intact.

'tg-admin update' does not overwrite your old dev.cfg or prod.cfg. You can call 'yourprojectname-start.py' to start up your project using the old config files, or you can use 'start-yourprojectname.py' to start using the new configuration files. Migration to the new files should be straightforward, and is probably as simple as copying the database configurations from the old files to the new ones. Once you have fully migrated to 0.9, you should delete dev.cfg, prod.cfg, and yourprojectname-start.py.

Make Static File Paths Absolute

CherryPy 2.2 requires that paths to static files be absolute. While you might think this would prevent projects from being deployed on different machines, TurboGears provides a function 'absfile' to help maintain portability. If your package name is 'bigboy', in 0.8 you would say:

Now, you must now specify:

top_level_dir is the directory where the top level of your project is located. You can also use package_dir which is the same directory the config file is located in.

'tg-admin update' should take care of the /static and /favicon.ico cases (in the new config files), but if you have any custom static files or folders, you will need to make a change to make sure that the file paths are absolute.

Methods Must Explicitly Allow JSON

In order to prevent accidentally exposing information that perhaps everyone shouldn't see, exposed methods no longer automatically provide JSON output when the url contains 'tg_format=json'. Instead, you must explicitly state when a method is going to provide JSON output. This can be done two different ways:

  1. Enable JSON in app.cfg If you would like to have the same behavior as existed in v0.8 (i.e. JSON output is always exposed), you can globally enable it in your app.cfg with:
    tg.allow_json = True
  2. Enable JSON only for specific methods If you would like to only let specific methods return JSON (which is probably smart from a security perspective), you can do so using the 'allow_json' parameter in the '@turbogears.expose' decorator, like this:

    Or, if you really only care to have JSON output for a method, you can use the 'format' parameter, like this:

Changing from std. to tg. in your templates

The "std" object that appears in your template namespace that holds useful values and functions has been renamed "tg". You should be able to do a search and replace in your template files to swap "std." with "tg.".

Other Incompatibilities

There are a couple other changes that probably won't impact most projects, but will cause things to not work if you are using them.

Depreciated Items

The following items will work in 0.9, but will be changing in the future. You should migrate away from any usage of these items as you are able to.

Updating from 0.5 to 0.8

0.8 has a number of minor backwards incompatible changes. There are only two such changes that you'll likely need to take action on.

The primary one is the renaming of the turbogears* variables. You'll want to do project wide search/replace for these values.

Search forReplace with
turbogearshtmltg_template
turbogearsfmttg_format
turbogearsflashtg_flash
turbogearsjstg_js

The other noticeable change that you'll come across is that turbogears-admin.py has been renamed to tg-admin. Note that in addition to the base name change, you no longer need to add the .py on the end.

Though they are less likely to pose problems for you, you may wish to check out the complete changelog for additional changes.

Download

TurboGears 1.0b1

September 7, 2006

Features: Widgets, ModelDesigner, Identity framework, FastData, and much more

Download now button Upgrade instructions button

Download development version from SVN

Get involved

Order the DVD and more!

The TurboGears Ultimate DVD is now shipping! More than 5 hours of video!
We also have the marble rolling mini-framework you've been looking for.

Hosting Options

TurboGears can be hosted in many places, but we've got 4 of the best choices picked out. Super simple TurboGears use from WebFaction starting at $11.50 a month or, if you need more control, dedicated servers from ServerPronto starting at just $29.95 a month. Check it out
last updated: Sep 08, 2006
Comment on this page