Created
October 5, 2011 10:20
-
-
Save adaptives/1264110 to your computer and use it in GitHub Desktop.
LPTHW Exercise 51 - Templates
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
import web | |
urls = ( | |
'/hello', 'Index' | |
) | |
app = web.application(urls, globals()) | |
render = web.template.render('templates/', base="layout") | |
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
<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> |
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
$def with (greeting) | |
<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! |
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
$def with (content) | |
<html> | |
<head> | |
<title>Gothons From Planet Percal #25</title> | |
</head> | |
<body> | |
$:content | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment