On Sun, May 2, 2010 at 5:00 AM, Felix Schwarz <[email protected]> wrote: > > some nice people on the IRC channel pointed out that url_for is deprecated > and I should use pylons.url > > However pylons.url does not seem to obey my PrefixMiddleware configuration. > How can I make pylons.url aware of the configuration? Or is that just a > stupid thing on my side?
I've about had it with Routes. Its syntax allows too much ambiguity, and the older docs have sent people in all sorts of questionable directions. I'm half inclined to release the Routes2/Routes-exp code under a different name, with no ambiguous syntaxes or backward compatibility allowed. As if I had time to. The docs you're looking at are for 0.9.7, which was released over a year ago. Since then there have been advances in Routes and best practices. It looks like Pylons 1.0 needs to be released sooner rather than later, to tighten up the docs. The current Routes docs are here: http://routes.groovie.org/ . Then unfinished-but-better-than-0.9.7 Pylons docs are here: http://pylonshq.com/docs/en/1.0/ . The best way to generate routes is by name: # Named generation map.connect("documents", "/documents/{action}", controller="documents") url("documents", action="foo") => "/prefix/documents/foo" In this case, the first positional arg is the route name, not the controller per se. For external URLs and special cases you can use a literal URL: # External URL (no route for it) url("/documents", action="foo") => "/prefix/documents?action=foo" This is like your first example. The first arg begins with a slash, so it's taken as a literal URL rather than a name. It does not match any route, so there are no path variables or extra variables ("defaults") to consider. All keyword args are converted to query parameters. Of course, Pylons does not look for the action in a query parameter, so it would not be able to process this URL. # Generic /controller/action URL map.connect("/{controller}/{action}") url(controller="documents", action="foo") => "/prefix/documents/foo" This is less reliable than named generation, but it has been traditional in Pylons, and it's safe as long as there's only one route that could plausably match. If any of the above don't handle the prefix properly, it's probably a bug so let us know. > The [old] docs say: >> The following rules are used to determine when and how to keep the >> current requests parameters: >> * If the controller is present and begins with ‘/’, no defaults are >> used "No defaults are used" means it will ignore the extra variables in the route definition (which were then called "defaults"). I'm not sure if the statement is still true, or if it ever was. I never considered putting a slash in a controller variable (controller="/documents") >> * If the controller is changed, action is set to ‘index’ unless >> otherwise specified This is no longer the default case. If the action is not specified either in the route definition or in the generation args, no action will be passed to Pylons, which will raise an error. -- 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.
