Hi,
I'm trying to do custom routes with TG2 and failing so far. The
instructions in http://turbogears.org/2.0/docs/main/RoutesIntegration.html
tell you to:

"you can easily do that, just by providing your own function to set up
the routes map. You can update the routes defaults by overriding the
setup_routes method of the base_config object in app_cfg.py."

Well, it's not that clear . setup routes() is a method of AppConfig.
If you just implement your own function in app_cfg.py it is never
called. You can subclass AppConfig and provide your own setup_routes()
method or you can create a custom setup_routes() function and assign
it to the original AppConfig before you instantiate base_config:

AppConfig.setup_routes = custom_setup_routes
base_config = AppConfig()

You will also need to import a bunch of stuff from tg.configuration
such as Mapper and config.

Once, I got that part right and my custom_setup_routes function was
actually called, it just did,'t work. I can't even get a simple hard-
coded path to work. Here is my custom_setup_routes() function:

def custom_setup_routes(self):
    """Setup the default TG2 routes

    Override this and set up your own routes maps if you want to use
routes.
    """
    #from dbgp.client import brk; brk(port=9011)
    map = Mapper(directory=config['pylons.paths']['controllers'],
                always_scan=config['debug'])

    map.connect('prefix/foo', controller='root', action='foo')

    # Setup a default route for the root of object dispatch
    map.connect('*url', controller='root',
action='routes_placeholder')

    config['routes.map'] = map


I expect that the /prefix/foo URL will result in a call to the foo()
method on my RootController, but it doesn't. The standard object
dospatch works just fine, so /foo does get to my foo() method.

Can someone tell me what I'm doing wrong and/or explain how to debug
routing and/or show a full-fledged example of custom routes in TG2?

Thanks, Carl

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to