Status: | Official |
---|
Table of Contents
If you are coming over from Pylons, or merging an existing Pylons application into a TG application, you might want to use your own routing scheme. This is perfectly allowable, TurboGears just sets up a very simple routing to kick off it’s Object Dispatch mechanism, but this can be augmented hower you desire. One thing to note, if you plan on mounting TurboGears controllers without using class instantiation, they must subclass a TurboGears Controller, complete with Dispatcher. Examples of classes like this are: TGController, WSGIAppController, and RestController.
Setup the default TG2 routes
Override this and setup your own routes maps if you want to use custom routes.
It is recommended that you keep the existing application routing in tact, and just add new connections to the mapper above the routes_placeholder connection. Lets say you want to add a tg controller SamplesController, inside the controllers/samples.py file of your application. You would augment the app_cfg.py in the following way:
from routes import Mapper
from tg.configuration import AppConfig
class MyAppConfig(AppConfig):
def setup_routes(self):
map = Mapper(directory=config['paths']['controllers'],
always_scan=config['debug'])
# Add a Samples route
map.connect('/samples/', controller='samples', action=index)
# Setup a default route for the root of object dispatch
map.connect('*url', controller='root', action='routes_placeholder')
config['routes.map'] = map
base_config = MyAppConfig()