views:

56

answers:

2

I'm trying to setup my Routes and enable an optional 'format' extension to specify whether the page should load as a standard HTML page or within a lightbox.

Following this http://routes.groovie.org/setting_up.html#format-extensions, I've come up with:

map.connect('/info/test{.format:lightbox}', controller='front', action='test')

class FrontController(BaseController):
    def test(self, format='html'):
        print format

This fails. My route gets screwed up and the URL appears as /front/test rather than /info/test. It's falling back to the /{controller}/{action}.

How do I allow for the format extension? :/

+1  A: 

Generally:

http://pylonsbook.com/en/1.1/urls-routing-and-dispatch.html#pylons-routing-in-detail

Routes then searches each of the routes in the route map from top to bottom until it finds a route that matches the URL. Because matching is done from top to bottom, you are always advised to put your custom routes below the ones that Pylons provides to ensure you don’t accidentally interfere with the default behavior of Pylons. More generally speaking, you should always put your most general routes at the bottom of the route map so that they don’t accidentally get matched before a more specific route lower down in the route map.

The MYYN
A: 

The first thing I'd check is that you're using routes 1.12. Several distros are still on 1.11, which doesn't support format extensions.

Second, check the order in which your routes are defined. It matters.

ssokolow
I'm using version 1.12.3. Following http://pylonsbook.com/en/1.1/urls-routing-and-dispatch.html#pylons-routing-in-detail, my routes are in between the predefined `error` and `'general'` routes
dave
In that case, my suggestion is to start narrowing down the scope of the problem. Have you tried commenting out the `/{controller}/{action}` route and removing the `{.format:lightbox}` portion of your URL to confirm that it works as expected without the extension specifier?
ssokolow
If I remove the format extension, all my routes work as expected. There's a few different ones in there mapping to various controllers/actions and they all work great. When I add the format extension, that one route breaks. I don't know if I've screwed up the actual route or how, I've assumed, that format will be passed to the controller (my `format` argument in the action)
dave
Have you tried just `{.format}` yet to see if the problem could be with the filter? If so, try making it a named route and generating a URL with it to see what routes thinks it should be.
ssokolow