On Sun, Mar 23, 2008 at 3:38 PM, Jonathan Vanasco <[EMAIL PROTECTED]> wrote: > > is there a way to test if a url is valid , or where it maps to? > > i can't find that within the pylons code > > use case: > i'm locking a project down to 'preview', and want to redirect > uncookied users to '/preview/%(original_request)' if that is a valid > url, and /preview otherwise.
You can check if there's a valid route by getting the routemapper out of the environ and trying to match it, but that won't tell you whether the controller and action exist. You'd have to duplicate Pylons' dispatching code to do that. Or you could make a subrequest and see if it raises an HTTP error, but that's a bit messy and you'd end up invoking the second page twice if it exists. Why can't you let the second request worry about it? Just redirect to /preview/*url assuming it will succeed, and have a catchall route after the other preview routes that catches invalid /preview/*url and redirects again to /preview. -- 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 -~----------~----~----~----~------~----~------~--~---
