views:

434

answers:

1

I am constructing a table of routes in my Pylons app. I can't get redirect() to work the way that it should work. I'm not sure what I'm doing wrong.

Here is an example of redirect() usage from the Routes documentation:

map.redirect("/home/index", "/", _redirect_code="301 Moved Permanently")

Here is what appears in my routing.py file:

map.redirect("/view", "/", _redirect_code="301 Moved Permanently")

Here is a route using redirect() that appears at the end of my routing.py file:

map.redirect('/*(url)/', '/{url}', _redirect_code="301 Moved Permanently")

This route works just fine, so I know that redirect() is present and functional. Therefore, I am doing something wrong in the /view redirect. I know this because when I point my browser at /view, I get the 404 page instead of getting redirected. Going to / works just fine, so I don't think that the problem is there, either. I think that redirect() in Routes is a great idea and I would like to be able to use it as intended, but I'm not sure what I'm doing wrong here.

ETA @jasonjs: I believe that no other route matches. When I try to access /view and then look at Paster's output, here's what I get:

21:22:26,276 DEBUG [routes.middleware] No route matched for GET /view

which seems pretty conclusive to me. I should mention that there is a route that matches POST requests to /view:

map.connect('/view', controller='view', action='search', conditions=dict(method=['POST'])

That route also works correctly, and I have it listed earlier in routing.py so that it tries to match that before it tries to match the /view[GET] route.

+1  A: 

That syntax works, so there must be something else going on.

Routes is sensitive to order. Is there another route above the redirect that would match /view to a controller that would return a 404?

Routes is also sensitive to trailing slashes. Did you accidentally type a trailing slash in the browser but not in the route, or vice versa?

Finally, in development.ini, if you set level = DEBUG under [logger_routes], you can then check the log messages after visiting /view to see what was matched.

ETA: I just tried putting a POST-matching rule before a redirect for the same path, and it worked as expected. Are you on the latest Routes version (1.11)? Otherwise I don't have anything else for you, not being able to see code. It may just be a matter of starting with a barebones test case and building up until it breaks, or taking things away until it works...

Jason S
Edited to reflect your request for information.
Krinn
Well, going from 1.10 to 1.11 worked, so thanks. I'll chalk it up to bugfixes.
Krinn