The default CherryPy routing style is based on instances of classes with methods decorated by @cherrypy.expose.
In the example below, these urls are provided by simple tweaking on otherwise ordinary classes.
/
/hello
/hello/again
/bye
/bye/again
I wonder if there is a way to achieve this using Flask's @route or some other decorator.
import cherrypy
class Root(object):
@cherrypy.expose
def index(self):
return 'my app'
class Greeting(object):
def __init__(self, name, greeting):
self.name = name
self.greeting = greeting
@cherrypy.expose
def index(self):
return '%s %s!' %(self.greeting, self.name)
@cherrypy.expose
def again(self):
return '%s again, %s!' %(self.greeting, self.name)
if __name__ == '__main__':
root = Root()
root.hello = Greeting('Foo', 'Hello')
root.bye = Greeting('Bar', 'Bye')
cherrypy.quickstart(root)