On 9/6/07, Andrey Gladilin <[EMAIL PROTECTED]> wrote: > What are the main differencies between TG2 dispatcher pylons one? Is there any > documentation regarding TG dispatcher?
In a Pylons application the URL sitemap and the controller+action structure are completely independent from each other. So /a, /b, /foo/part1, and /foo/part2 may correspond to actions a, b, c, and d in some controller, and /c may correspond to an action in another controller. You can move 'c' and 'd' to another controller without changing the URLs; you just change the Routes mapping rules. This brings a level of flexibility previously unavailable in Python web frameworks. Normally Routes maps the entire URL to a specific action, possibly converting trailing parts into action arguments (e.g., /articles/:year/:month:/:day/:id). But it's possible to wildcard the rest of the URL and let some other mechanism parse it. E.g., /articles/*url and /turbogears/*url, which would match /articles/MY/BIG/HUNKIN/ARTICLE/ID/WITH/SLASHES and /turbogears/my/turbogears/page. The wildcard part is passed as a single string in a routing variable, and the controller does whatever it wants with it. In TurboGears, a URL /a/b/part1 is translated to a.b.part1 using attribute-subattribute lookup. I haven't used TG for a while so I may not have the terminology or behavior exactly right. In TG 1, there's a "root" controller class mounted at "/" in CherryPy's URL space. You can mount other controllers below this, each corresponding to a URL "subdirectory". So 'a' is mounted inside the root, and 'b' inside a. I think this corresponds to class attributes in the parent controller. CherryPy follows the attribute chain through the subcontrollers until it reaches 'part1', which is a method. If the method has an @expose decorator, it's called as the "action". If the method is not exposed, you get a NotFound error -- this is a security feature. In TG 2, Routes handles the left side of the URL up to the TG application (which would be at "/" for a pure TG application). TurboGearsController .__call__ emulates CherryPy's dispatching for the rest of the URL. Which way is "better" depends on your philosophy. I've made several Quixote apps which have a similar dispatcher as CherryPy, and I thought it was cool. But after using Routes, I like its flexibility more. CherryPy 3 allows Routes dispatching as an option from what I hear. So I suspect this will become more popular among TurboGears programmers over time. -- Mike Orr <[EMAIL PROTECTED]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
