TurboGears: Integrating with mod_python

The SVN version of TG uses cherrypy-2.2.0-beta which, AFAIK, is not compatible with the mpcp script described at the other mod_python integration page.

I've managed to get it running using Robert Brewer's modpython_gateway.py. It has been tested on a Debian Sarge box, Apache 2.0.54 (worker MPM) and a backported libapache2-mod-python2.4 package from Ubuntu (the package didn't install cleanly and some black drudgery had to be done in order to get it working by hand so I will not post it here yet, if there's some demand I might try to build a better backport).

However, provided you can run your TG app with python2.3, you should be fine with Sarge's stock modpython2.3. (I'm a big fan of 2.4's syntax sugar so I couldn't resist :)

Quick recipe

  1. Install wsigiref, sudo easy_install wsgiref should get you going.
  2. Download Robert's script and place it inside wsgiref's package.
  3. * You'll need to write a script to start your TG app as start-yourapp.py will not work. It should be something like:

Make sure you don't make any reference to sys.argv (as modpython doesn't have a command line) and you use full paths (as Apache's working directory is /, like any well behaved unix daemon...). Don't forget to fix your paths and application name!.

Place this script in your application's package (where controllers.py lives), let's say you call it myapp_modpython.py.

Should get you going. Most of the configuration options don't add much to the understanding of this topic, The important stuff are the Python* directives.

Important things to consider: