dave
dave

Reputation: 7867

Python routes - I'm trying to set the format extension but it's failing

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? :/

Upvotes: 1

Views: 308

Answers (2)

ssokolow
ssokolow

Reputation: 15345

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.

Upvotes: 0

miku
miku

Reputation: 188064

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.

Upvotes: 1

Related Questions