Routes Documentation

Routes is a Python re-implementation of the Rails routes system for mapping URLs to application actions, and conversely to generate URLs. Routes makes it easy to create pretty and concise URLs that are RESTful with little effort.

Routes allows conditional matching based on domain, cookies, HTTP method, or a custom function. Sub-domain support is built in. Routes comes with an extensive unit test suite.

Current features:

  • Sophisticated route lookup and URL generation
  • Named routes
  • Redirect routes
  • Wildcard paths before and after static parts
  • Sub-domain support built-in
  • Conditional matching based on domain, cookies, HTTP method (RESTful), and more
  • Easily extensible utilizing custom condition functions and route generation functions
  • Extensive unit tests

Installing

Routes can be easily installed with pip or easy_install:

$ easy_install routes

Example

# Setup a mapper
from routes import Mapper
map = Mapper()
map.connect(None, "/error/{action}/{id}", controller="error")
map.connect("home", "/", controller="main", action="index")

# Match a URL, returns a dict or None if no match
result = map.match('/error/myapp/4')
# result == {'controller': 'error', 'action': 'myapp', 'id': '4'}

Documentation

Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.