Package: tgext.routes
About tgext.routestgext.routes provides a simple way to integrate routes based dispatch
into TurboGears2 applications.Installingtgext.routes can be installed both from pypi or from bitbucket:pip install tgext.routesshould just work for most of the usersRouting Single ActionsRoutes matching is done through the@routedecorator,
each exposed method can be bound to one or multiple routes.The only requirement is that you inherit from theRoutedControllerinstance.All routes registered through the@routedecorator are registered starting
from the controller mount point.The following example registers theentry_by_datemethod for urls like/date/2012-01and/date/2012-01-01:from tgext.routes import RoutedController, route

class DateController(RoutedController):
    @expose()
    @route('{year}-{month}', day=33)
    @route('{year}-{month}-{day}')
    def entry_by_date(self, year, month, day):
        return '%s ++ %s ++ %s' % (year, month, day)

class RootController(BaseController):
    date = DateController()

    @expose()
    def index(self):
        return 'Hello!'Keep in mind that as@exposewraps it, the method is still
accessible throughObjectDispatchrouting,@routecan just
register additional routes.If there is a route pointing to it, also actions that do not provide
an@exposedecoration are resolved, keep in mind that in that case
you will have to render template manually.In case you want to disableObjectDispatchyou can setdisable_objectdispatch=Trueinside the controller. Keep in mind that it will disableObjectDispatchfor the
whole controller and so you won’t be able to dispatch actions that do not provide
a route from that controller on.Routing Whole applicationRoutedControllercan also be mounted as the applicationRootController.
In that case instead of using the@routedecorator you can even provide
aroutes.Mapperobject as controllermapperattribute and register
all the routes of your application:class RootController(RoutedController):
    mapper = Mapper()
    mapper.connect('/', controller='home', action='index')
    mapper.connect('/json', controller='home', action='jsonexposed')
    mapper.connect('/unex', controller='home', action='unexposed')In this case thecontrollerargument is required and controller will be looked
up inside the path specified bytg.config['paths']['controllers']. In the previous
example aHomeControllerclass will be looked for into thehome.pymodule to
serve the/,/jsonand/unexpaths through itsindex,jsonexposedandunexposedmethods.In case both amapperattribute and@routedecorator are used inside the sameRoutedController, the@routedecorator is applied after the mapper routes.For more documentation about routes refer toRoutes DocumentationContinuing with ObjectDispatchWhen using tgext.routes as the primary routing method it is possible to tell
it to continue with ObjectDispatch (or any specific dispatch method provided
by the target controller) using_dispatchas theactionof the route.By default as routes are matched exactly providing a_dispatchaction will
provide no remainder, so it will only dispatch toindexmethod of the target controller.
To continue dispatching with a remaining part of the url you can use an_dispatchlabel:mapper.connect('/forsub{_dispatch:.*?}', controller='home',  action='_dispatch')This will dispatch toHomeControllercontinuing with ObjectDispatch for anything
that cames after/forsubpart of the url.