root/tags/cherrypy-2.0.0/cherrypy/tutorial/01_helloworld.py
| Revision 102 (checked in by dpotter, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | """ |
| 2 | Tutorial 01 - Hello World |
| 3 | |
| 4 | The most basic (working) CherryPy application possible. |
| 5 | """ |
| 6 | |
| 7 | # Import CherryPy global namespace |
| 8 | from cherrypy import cpg |
| 9 | |
| 10 | class HelloWorld: |
| 11 | """ Sample request handler class. """ |
| 12 | |
| 13 | def index(self): |
| 14 | # CherryPy will call this method for the root URI ("/") and send |
| 15 | # its return value to the client. Because this is tutorial |
| 16 | # lesson number 01, we'll just send something really simple. |
| 17 | # How about... |
| 18 | return "Hello world!" |
| 19 | |
| 20 | # Expose the index method through the web. CherryPy will never |
| 21 | # publish methods that don't have the exposed attribute set to True. |
| 22 | index.exposed = True |
| 23 | |
| 24 | # CherryPy always starts with cpg.root when trying to map request URIs |
| 25 | # to objects, so we need to mount a request handler object here. A request |
| 26 | # to '/' will be mapped to cpg.root.index(). |
| 27 | cpg.root = HelloWorld() |
| 28 | |
| 29 | # Start the CherryPy server using the configuration file tutorial.conf. |
| 30 | cpg.server.start(configFile = 'tutorial.conf') |
| 31 |
Note: See TracBrowser for help on using the browser.

