Package cherrypy :: Package tutorial :: Module tut02_expose_methods
[hide private]
[frames] | no frames]

Source Code for Module cherrypy.tutorial.tut02_expose_methods

 1  """ 
 2  Tutorial - Multiple methods 
 3   
 4  This tutorial shows you how to link to other methods of your request 
 5  handler. 
 6  """ 
 7   
 8  import cherrypy 
 9   
10   
11 -class HelloWorld:
12
13 - def index(self):
14 # Let's link to another method here. 15 return 'We have an <a href="show_msg">important message</a> for you!'
16 index.exposed = True 17
18 - def show_msg(self):
19 # Here's the important message! 20 return "Hello world!"
21 show_msg.exposed = True
22 23 import os.path 24 tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') 25 26 if __name__ == '__main__': 27 # CherryPy always starts with app.root when trying to map request URIs 28 # to objects, so we need to mount a request handler root. A request 29 # to '/' will be mapped to HelloWorld().index(). 30 cherrypy.quickstart(HelloWorld(), config=tutconf) 31 else: 32 # This branch is for the test suite; you can ignore it. 33 cherrypy.tree.mount(HelloWorld(), config=tutconf) 34