Using mappings in CherryPy

前端 未结 1 1863
野的像风
野的像风 2021-01-22 15:30

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

1条回答
  •  无人及你
    2021-01-22 15:44

    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.

    0 讨论(0)
提交回复
热议问题