Starting CherryPy application with HTTP method dispatcher
Question: I am new to cherrypy, and I am trying to start a simple application using the
method dispatcher. I have been trying to learn about cherrypy configuration
using this site:
<https://cherrypy.readthedocs.org/en/3.2.6/concepts/config.html>, but I am
still not understanding what I am doing wrong. When I start the application,
and go to 127.0.0.1:8080, I get the error message: the path '/' was not found.
Here is my python file that I am using to start the application:

    
    
    import cherrypy
    import re
    import json
    import requests
    
    class root(object):
    
        def GET(self):
            return "<html> <p> Hello </p> </html>"
    
    
    
    if __name__ == '__main__':
    
        conf = {'server.socket_host': '127.0.0.1', 
                'server.socket_port': 8080}
        cherrypy.config.update(conf)
    
        cherrypy.tree.mount(root(), '/', {
            '/': {
                'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
                'tools.trailing_slash.on': False,
            }
        })
        cherrypy.engine.start()
        cherrypy.engine.block()
    

I am trying to set up this root application so that I can use the _cp_dispatch
function to dispatch the application based on the path given. Is this the best
way of doing it?


Answer: You have to expose the object defining an attribute "exposed":

    
    
    import cherrypy
    import re
    import json
    import requests
    
    class root(object):
        exposed = True
    
        def GET(self):
            return "<html> <p> Hello </p> </html>"
    
    
    
    if __name__ == '__main__':
    
        conf = {'server.socket_host': '127.0.0.1',
                'server.socket_port': 8080}
        cherrypy.config.update(conf)
    
        cherrypy.tree.mount(root(), '/', {
            '/': {
                'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
                'tools.trailing_slash.on': False,
            }
        })
        cherrypy.engine.start()
        cherrypy.engine.block()
    

