Created
October 5, 2011 10:09
-
-
Save adaptives/1264092 to your computer and use it in GitHub Desktop.
LPTHW Exercise 51 - Form Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This app.py handles POST data from the hello_form | |
import web | |
urls = ( | |
'/hello', 'Index' | |
) | |
app = web.application(urls, globals()) | |
render = web.template.render('templates/') | |
class Index: | |
def GET(self): | |
return render.hello_form() | |
def POST(self): | |
form = web.input(name="Nobody", greet="Hello") | |
greeting = "%s, %s" % (form.greet, form.name) | |
return render.index(greeting = greeting) | |
if __name__ == "__main__": | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This template works with the modifications to handle POST data --> | |
<html> | |
<head> | |
<title>Sample Web Form</title> | |
</head> | |
<body> | |
<h1>Fill Out This Form</h1> | |
<form action="/hello" method="POST"> | |
<p> | |
A Greeting: <input type="text" name="greet" /> | |
</p> | |
<p> | |
Your Name: <input type="text" name="name" /> | |
</p> | |
<p> | |
<input type="submit" /> | |
</p> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This template works with the modifications to handle POST data --> | |
<html> | |
<head> | |
<title>Gothons Of Planet Percal #25</title> | |
</head> | |
<body> | |
<p> | |
<a href="/hello">Home</a> | |
</p> | |
$if greeting: | |
I just wanted to say <em style="color: green; font-size: 2em;">$greeting</em>. | |
$else: | |
<em>Hello</em>, world! | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment