Last active
August 29, 2015 14:08
-
-
Save jirihnidek/9fc2466705ee44836dcf to your computer and use it in GitHub Desktop.
WebPy Templetor Example
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) | |
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>$content.title</title> | |
</head> | |
<body> | |
$:content | |
</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
$var title: Introduction | |
<h1>Hello World!</h1> |
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 module tries to generate page with templator | |
""" | |
# | |
# To test the application run application with: | |
# | |
# python ./webpy_template.py | |
# | |
# and type following URI in browser address bar: | |
# | |
# http://localhost:8080/ | |
# | |
import web | |
URLS = ( | |
'/', 'HandleIndex' | |
) | |
RENDERER = web.template.render('', base='base') | |
class HandleIndex(object): | |
""" | |
Application handling index | |
""" | |
def __init__(self): | |
""" | |
Constructor of HandleIndex | |
""" | |
print "Starting index app ..." | |
def __del__(self): | |
""" | |
Destructor of HandleIndex | |
""" | |
print "Ending index app ..." | |
def GET(self): | |
""" | |
Callback method handling HTTP GET request | |
""" | |
return RENDERER.intro() | |
def main(): | |
""" | |
Main function starting app | |
""" | |
http_app = web.application(URLS, globals()) | |
http_app.run() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GitHub Gist does not support directories. Thus, real application would contain html templates in some directory (e.g. templates) and creating renderer would look like this:
RENDERER = web.template.render('templates', base='base')