|
Revision 1219
(checked in by fumanchu, 2 years ago)
|
Changed server.start to server.quickstart, and server.start_all to server.start.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
""" |
|---|
| 2 |
Tutorial - Passing variables |
|---|
| 3 |
|
|---|
| 4 |
This tutorial shows you how to pass GET/POST variables to methods. |
|---|
| 5 |
""" |
|---|
| 6 |
|
|---|
| 7 |
import cherrypy |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
class WelcomePage: |
|---|
| 11 |
|
|---|
| 12 |
def index(self): |
|---|
| 13 |
|
|---|
| 14 |
return ''' |
|---|
| 15 |
<form action="greetUser" method="GET"> |
|---|
| 16 |
What is your name? |
|---|
| 17 |
<input type="text" name="name" /> |
|---|
| 18 |
<input type="submit" /> |
|---|
| 19 |
</form>''' |
|---|
| 20 |
index.exposed = True |
|---|
| 21 |
|
|---|
| 22 |
def greetUser(self, name = None): |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
if name: |
|---|
| 32 |
|
|---|
| 33 |
return "Hey %s, what's up?" % name |
|---|
| 34 |
else: |
|---|
| 35 |
if name is None: |
|---|
| 36 |
|
|---|
| 37 |
return 'Please enter your name <a href="./">here</a>.' |
|---|
| 38 |
else: |
|---|
| 39 |
return 'No, really, enter your name <a href="./">here</a>.' |
|---|
| 40 |
greetUser.exposed = True |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
cherrypy.tree.mount(WelcomePage()) |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
if __name__ == '__main__': |
|---|
| 47 |
import os.path |
|---|
| 48 |
cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf')) |
|---|
| 49 |
cherrypy.server.quickstart() |
|---|
| 50 |
cherrypy.engine.start() |
|---|