Of course, having just one method is useless and wasteful. Additional methods may certainly be created, and they may be access by appending their names to the address. For example, let's create a file that contains multiple methods and test it out: import cherrypy class MultiMethod: def index ( self ): cherrypy.root = MultiMethod() As you can see, each method contains a link to the next method. Of course, having a bunch of methods thrown around a file isn't going to help you when it comes to organization. That's why CherryPy also allows for multiple objects in your applications, as seen here: import cherrypy class DefaultClass: def index ( self ): class A: def index ( self ): class B: def index ( self ): class C: def index ( self ): cherrypy.root = DefaultClass() If you run the application, you will see that we have various objects and their methods mapped to different addresses: http://localhost:8080 http://localhost:8080/A http://localhost:8080/A/a http://localhost:8080/B http://localhost:8080/B/b http://localhost:8080/C http://localhost:8080/C/c Notice that we assign an instance of each class to a variable under root. This is necessary for CherryPy to figure out which objects you want to let users access and where you want each object in the address map. You could also nest objects within the map: import cherrypy class DefaultClass: def index ( self ): class A: def index ( self ): class B: def index ( self ): class C: def index ( self ): cherrypy.root = DefaultClass() cherrypy.config.update ( file = 'development.conf' ) Now, C is inside B, which is inside A: http://localhost:8080 http://localhost:8080/A http://localhost:8080/A/B http://localhost:8080/A/B/C
blog comments powered by Disqus |
|
|
|
|
|
|
|