I'm currently working on some Routes features that are
rather useful,
if not important, for application composition. The main one
being the
ability to use relative paths with url_for/link_to instead
of hard-
coding them, which means that if the application is running
under a
different mount point, the URL will still be correct.
The other useful ability, which should help with everyone's
favorite
buzz-word, DRY, is being able to use static named routes.
Here's what
it looks like:
map.connect('search', 'http://www.google.com/',
_static=True)
url_for('search', v='routes') -> http://www.google.com
/?v=routes
Static routes are only used for generation, not matching,
and they
can be relative too if there's some common 'raw' URL you
find
yourself frequently linking to.
map.connect('images', '/gallery/images/view/all',
_static=True)
url_for also supports passing it raw URL's:
url_for('http://amazon.com/',
search='newton') -> http://
amazon.com/?search=newton
If you use a relative path beginning with '/', it will
ensure that
the link works in various deployment scenarios:
# App is mounted at /App2
url_for('/css/main.css') -> /App2/css/main.css
The features I just mentioned are available now in the
1.2dev,
(easy_install -U Routes==dev), or you can wait till early
next week
for the 1.2 release.
Cheers,
Ben
|