Skip to content

Instantly share code, notes, and snippets.

@jirihnidek
Last active August 29, 2015 14:08
Show Gist options
  • Save jirihnidek/9fc2466705ee44836dcf to your computer and use it in GitHub Desktop.
Save jirihnidek/9fc2466705ee44836dcf to your computer and use it in GitHub Desktop.
WebPy Templetor Example
$def with (content)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>$content.title</title>
</head>
<body>
$:content
</body>
</html>
$var title: Introduction
<h1>Hello World!</h1>
"""
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()
@jirihnidek
Copy link
Author

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment