Skip to content Skip to sidebar Skip to footer

Using Mappings In Cherrypy

In the 'Dispatching / Other Dispatchers' section of the CherryPy documentation, there is an example of Django-style regular-expression-to-view-function mapping definition, but ther

Solution 1:

There's not any extra step required. During a request, cherrypy.tree performs a first routing stage, where the incoming request is mapped to an Application using its path-to-app mapping. When you call tree.mount(root=None, script_name='/', config=conf) at startup, the Tree creates a cherrypy.Application for you behind the scenes and mounts it at '/'.

Once the Application is found, its config takes over, and the "request.dispatch" config for the example app in the docs says "use the RoutesDispatcher for all URI's in this app". That RoutesDispatcher instance will then pass control of the request to the appropriate Controller.

The regex example in the docs isn't even that well-developed. You'd need to write a Dispatcher which uses it. That process "only" needs to find the handler and collect request.config, but those two activities can be very complex depending on the dispatch style chosen. See the existing dispatchers for inspiration.

Post a Comment for "Using Mappings In Cherrypy"