[EMAIL PROTECTED] schrieb: > I want to do a redirect from a controller > to a URL relative to the URL of the controller.
> I'm guessing this is a common need, so there's probably some simple > way to do it, but I haven't figured it out yet ;) If I understand you correctly, you want to find out, where your controller is mounted, i.e. what its URL is. Suprisingly, the solution isn't very obvious, but fortunately this has been discussed before: http://tinyurl.com/2p5th6 >From the solution presented in this thread, I have created a base class for my controllers, that provides a 'root_url' property. Here's the code: class BaseController(controllers.Controller): """Base CherryPy controller class with useful utility methods.""" def _get_root_url(self): return self.breadcrumbs[-1][0] root_url = property(_get_root_url) def _get_breadcrumbs(self): try: return self._breadcrumbs except AttributeError: cherry_trail = cherrypy._cputil.get_object_trail() href = '/' crumbs = [('/', 'Home')] for item in cherry_trail: if isinstance(item[1], controllers.RootController): continue if isinstance(item[1], controllers.Controller): href = "%s%s/" % (href, item[0]) crumbs.append((href, getattr(item[1], 'title', item[1].__class__.__name__))) self._breadcrumbs = crumbs return crumbs breadcrumbs = property(_get_breadcrumbs) HTH, Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

