close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 6 (modified by cmlenz, 14 years ago) (diff)

--

URL Routing and Generation

The diva.routing module provides dispatching of requests to request handlers based on the requested path, as well as the generation of concrete URLs based on the routing.

Routing Configuration File

While routes can of course be set up programatically, a simple configuration file format is also supported.

A simple example:

home:           /                       -> geddit.controllers:index
feed:           /feed                   -> geddit.controllers:feed
info:           /info/{id}              -> geddit.controllers:info
comment:        /info/{id}/comment      -> geddit.controllers:comment
submit:         /submit                 -> geddit.controllers:submit

media:          /media/{filename:.+}    -> diva.static:directory
    path = "%(here)s/static/"

Every route is on a single line, with three different parts:

  • the name of the route (optional)
  • the path pattern with variable parts enclosed in curly braces, and
  • the target function that should handle requests matching that pattern (optional).

Additional indented lines can be provided to set default values for parameters that get passed on to the request handler. The value of these parameters can be any Python expression.

If no name is specified for a route, URLs for that route can not be generated by name, but only based on the function object. If no target is specified, the route is only used for generating links, not for dispatching requests.

API Documentation

Error: Macro PythonDoc(trunk, diva.routing) failed
Unsupported version control system "svn": No module named svn