Mark,
Thanks for the quick response. It didn't work though. My
RootController now subclasses tg.controllers.DecoratedController and I
get the following error even on http://localhost:8080/ (the root):

Module tg.controllers:125 in _perform_call
>>  controller.decoration.run_hooks('before_validate', remainder,
AttributeError: 'function' object has no attribute 'decoration'


The code expects 'controller' to be an object with a 'decoration'
attribute, but in my case the controller is the __before__ method of
RootController:

>>> controller
<bound method RootController.__before__ of
<nine.controllers.root.RootController object at 0x99a3d0>>

Is it possible to post a fully working TG2 custom routes example? It
doesn't even have to be the entire project just the differences from a
standard quickstarted project.

Thanks, Carl







On Mar 13, 7:40 am, Mark Ramm <[email protected]> wrote:
> Yea, those docs are missing some important details.
>
> One think you do need to know is that the
> TGController/ObjectDispatchController expects to be routed to for
> object dispatch, not for a final page.
>
> So you want to use DecoratedController when defining your own custom routes.
>
> All of this should go on the RoutesIntegration page.
>
> --Mark
>
>
>
> On Fri, Mar 13, 2009 at 6:23 AM, Carl <[email protected]> wrote:
>
> > Hi,
> > I'm trying to do custom routes with TG2 and failing so far. The
> > instructions inhttp://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
>
> --
> Mark Ramm-Christensen
> email: mark at compoundthinking dot com
> blog:www.compoundthinking.com/blog
--~--~---------~--~----~------------~-------~--~----~
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