On 6/20/07, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: > > Maybe somebody has a simple solution for the following problem with TG > controllers. > > I have two methods in the same controller like that: > > @expose() > def page(self, nr=0): > ... > > @expose() > def sibling(self): > ... > > Now I want to generate a *relative* link from "page" to "sibling". The > problem is that if page was called like "page?nr=3", then the link would > be just "sibling", but when page was called as "page/3", then link > should be "../sibling". > > So what I need is a relative link to the respective controller, which is > '../' times the number of positional arguments. > > Is there an easy way to determine that number? > > Of course I could > > def page(self, *args): > nr = args and args[0] or 0 > base_url = '../'*len(args) > > but that's ugly and I loose the possibility to pass the nr parameter as > part of the query string. > > Another possibility is to always work with absolute paths, but I prefer > using relative paths as much as possible, and this allows me to put the > controller anywhere in the hierarchy. > take a look at cherrypy.request, in it you have a lot of convenience methods that will help you work this out like browser_url, request.path,etc.
> -- 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 -~----------~----~----~----~------~----~------~--~---

