Contents
This page explains some of inner workings of TurboGears. This may be interesting to users wanting to extend TurboGears or for prospective core TG developers. While we try to be as accurate as we can and as detailed as necessary, the definite reference is always the source!
What happens when you start a TurboGears application until it is ready to process requests? How are the bits and pieces that make up the TurboGears framework assembled together? Please read the following section to learn more than you probably wanted to know!
Somebody (you, an init script, supervisor, mod_wsgi) runs the application’s start script. It simply imports the start function from the command module of the app and runs it.
The start function looks for a deployment configuration file in several places (see comments in command.py) and loads it, as well as the configuration from the config/*.cfg files in your app’s package. Parsing the configuration also triggers setting up the logging handlers etc.
It imports the Root controller class from the app’s controllers module, instantiates it, and passes it to the turbogears. start_server function (imported from turbogears.startup).
start_server mounts the root controller to the CherryPy object tree and starts the CherryPy server.
This triggers calling the turbogears.startup. start_turbogears function, because it is subscribed for being called on start with the CherryPy engine. This function handles the remaining initialization tasks (in given order):
Loads the template engines and the base templates.
Turns off CherryPy’s debug logging filter (which CherryPy normally turns on by default in development mode).
Adds a static filter for TurboGears’s static files (URL "/tg_static").
Adds a static filter for TurboGears’s JavaScript files (URL "/tg_js").
Adds the CherryPy decoding tool and disables the CherryPy encoding tool on the root URL ("/").
Adds the following CherryPy hooks and tools:
When in development mode, registers the server with the Bonjour framework, if available.
Calls turbogears.database. bind_metadata when using SQLAlchemy.
Loads all turbogears.extensions entry points and calls their start_extension method. The standard extensions included with TurboGears are:
Loads the IdentityVisitPlugin, which creates the identity data model if necessary, instantiates an identity provider, and registers itself as a visit plugin.
Calls the callables registered in turbogears.call_on_startup.
Starts the TurboGears scheduler if enabled.