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

Source Code for Module cherrypy.tutorial.tut01_helloworld

 1  """ 
 2  Tutorial - Hello World 
 3   
 4  The most basic (working) CherryPy application possible. 
 5  """ 
 6   
 7  # Import CherryPy global namespace 
 8  import cherrypy 
 9   
10   
11 -class HelloWorld:
12 13 """ Sample request handler class. """ 14
15 - def index(self):
16 # CherryPy will call this method for the root URI ("/") and send 17 # its return value to the client. Because this is tutorial 18 # lesson number 01, we'll just send something really simple. 19 # How about... 20 return "Hello world!"
21 22 # Expose the index method through the web. CherryPy will never 23 # publish methods that don't have the exposed attribute set to True. 24 index.exposed = True
25 26 27 import os.path 28 tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') 29 30 if __name__ == '__main__': 31 # CherryPy always starts with app.root when trying to map request URIs 32 # to objects, so we need to mount a request handler root. A request 33 # to '/' will be mapped to HelloWorld().index(). 34 cherrypy.quickstart(HelloWorld(), config=tutconf) 35 else: 36 # This branch is for the test suite; you can ignore it. 37 cherrypy.tree.mount(HelloWorld(), config=tutconf) 38