One note about Nathan's response; you need to derive your sub
controller from turbogears.controllers.Controller

Another note about your dymamic template question, you can return a
non-dict aswell, if you return a string, its sent as-is. With that in
mind, you can create a generic 'skin' method, that either inserts
tg_template into your dict, or returns the templated output directly,
which your controller method can than return.

Nathan wrote:
> > another, more basic question - my app has both an admin area and a
> > public area. rather than stuff all the logic into one controllers.py
> > module, it seems like the thing to do is tell turbogears to use one
> > controllers module for /admin and another for everything else. is there
> > a recommended pattern for this?
>
> Controllers are just python classes, so if you want to write a
> controller for another portion of your site just import a new class.
> As an example, you want to write an admin class that would control the
> /admin branch of your site. So open up a new module, admin.py, and
> import the appropriate turbogears stuff from the top of controller.py,
> then create a class just like Root.
>
> Example:
> class Admin:
>     @expose(html="whatever")
>     def index(self):
>         hello = "hello, world!"
>         return dict(hello=hello)
>
> In the original controller.py you then need to import this using the
> import command, so you would need to add something like:  "from admin
> import Admin" which will expose that class to the controller.
>
> Finally, to link that class to your main controller so that it will
> handle "/admin" you need to add a reference in the Root class, like
> this:
>     admin = Admin()
>
> What that does is simple, when TG comes across "/admin" it will look
> into Root and see what handles it, instead of finding "def
> somename(self):" it instead finds "admin=Admin()" and knows to then
> check the Admin class for a "def index(self):" to serve the request.
> All the same TG rules apply when constructing your Admin class.
>
> Hope that helps. I'm sure that's explained somewhere more concisely,
> but I'm too tired to look for it :)
> 
> 
> Nathan


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to