<script>
% for route in request.registry.getUtility(IRoutesMapper).get_routes():
APP.config.routes["${route.name}"] = "${route.path}";
% endfor
</script>
so that i can create URLs in javascript with a function like
APP.route = function (name, args) {
var path = APP.config.routes[name];
for (key in args) {
if (args.hasOwnProperty(key) && args[key] !== undefined) {
path = path.replace('{' + key + '}', args[key]);
}
}
return path;
};
The above only works if the match pattern does only contain names in
curly braces, but could be extended to massage more complex patterns
into this simple form ({id:\d+} -> {id}, ...).
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>
good question. maybe introspection [1] would work, too?
[1] http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/introspector.html
Is "request.registry.getUtility(IRoutesMapper).get_routes()" an
official Pyramid api or is it just a implementation detail that may
change without prior notice?
No plans to change the API. The first beta is due soon, FWIW.
- C