Search code examples
cherrypy

Return the exposed callable page handler that is used for a route


Using the simple application:

import cherrypy

class Root(object):
    @cherrypy.expose
    def index(self):
        return "Hello World!"

if __name__ == '__main__':
   cherrypy.quickstart(Root(), '/')

Is there a way I can hook into the dispatching process and get the name of which handler is to be called? In this instance, when I go to /, I want to be able to print index or whatever the name of the exposed method for that route is. It seems like a before_handler or before_finalize hook would be what I want, but not clear how to use them.


Solution

  • Using a before_handler hook, I was able to retrieve it through request.handler.callable