Routes


Route Recipes

A few common things people will most likely want to setup with Routes.

Adding a Root/Default Page

Despite being considered the default route, m.connect(':controller/:action/:id') won't actually call any of your controllers if you give it a URL like '/'. When many people think of their default page, they're thinking about what happens when you go to http://somehost.com/.

To setup a controller/action to handle this case, the route path will actually be empty. Here's an example:

m.connect('', controller='blog', action='index')

# Or for a named home route
m.connect('home', '', controller='blog', action='index')

# Which you then could use like so:
url_for('home')

Special Processing of a File

Perhaps you have a set of normal files available, and would like to enable a special operation on them. In this case we'll use a fictitious action called filter that is assumed to exist for our controllers:

m.connect('*file/:controller', action=filter)

Now we can match any URL that has a valid controller name at the end of it. This is then called with everything before the controller as the file keyword argument.