pecan.routing – Pecan Routing

The pecan.routing module is the basis for all object-dispatch routing in Pecan.

pecan.routing.lookup_controller(obj, remainder, request=None)

Traverses the requested url path and returns the appropriate controller object, including default routes.

Handles common errors gracefully.

pecan.routing.find_object(obj, remainder, notfound_handlers, request)

‘Walks’ the url path in search of an action for which a controller is implemented and returns that controller object along with what’s left of the remainder.


This function is used to define an explicit route for a path segment.

You generally only want to use this in situations where your desired path segment is not a valid Python variable/function name.

For example, if you wanted to be able to route to:


…the following is invalid Python syntax:

class Controller(object):

    with-dashes = SubController()

…so you would instead define the route explicitly:

class Controller(object):

pecan.route(Controller, 'with-dashes', SubController())