Seems like you're mostly on track.

1) class Second doesn't have to extend anything (but it can).
2) The url you typed had a capitol 'S', where is should have a lower
case 's'. If you have to have an upper case S you could rename
Root.second to Root.Second or you can look into implementing a
'default' method.
3) The following lines are extraneous...

>     @turbogears.expose( html="project.templates.welcome" )

>         import time
>         return dict( now=time.ctime() )
>
>     def hi( self ):
>         return "hi"

Here's what I would do with your example:

import turbogears
from turbogears import controllers

class Second:

    @turbogears.expose()
    def oneplusone( self ):
        return "2"

    @turbogears.expose()
    def twoplustwo( self ):
        return "four"


class Root(controllers.RootController):

    second = Second()

    @turbogears.expose()
    def index(self):
        return "Hi"

If you're running this with development defaults, you should be able to
access the following urls and see what you'd expect:

http://localhost:8080/ --> Hi
http://localhost:8080/second/oneplusone --> 2
http://localhost:8080/second/twoplustwo --> four

Good luck!

andrew wrote:
> I know this should be easy, but I am trying to assimilate cherrypy,
> sqlobject, kid, and the TG glue all in one day.
>
> What is the write way to inform TG about my second controller ?
>
> I want to be able to go to a URL like
> http://somewhere/Second/oneplusone and get my new controller in the
> loop.
>
> What is the write way to do this ??
>
> -- thanks a bundle...Andrew
>
>
> import turbogears
> from turbogears import controllers
> import cherrypy
> #from model import Page, hub
>
> #========================================
>
> class Second( controllers.Root ):
>
>     @turbogears.expose()
>     def oneplusone( self ):
>         return "2"
>
>     @turbogears.expose()
>     def twoplustwo( self ):
>         return "four"
>
> #========================================
>
> class Root( controllers.Root ):
>
>     second = Second()
>
>     @turbogears.expose( html="project.templates.welcome" )
>     def index( self ):
>         return "hi"
>         import time
>         return dict( now=time.ctime() )
>     
>     def hi( self ):
>         return "hi"

Reply via email to