How do I use template.py templates?

Asked by Eleanor Berger

How do I use Templator, the built-in templating package?

Question information

Language:
English Edit question
Status:
Solved
For:
web.py Edit question
Assignee:
No assignee Edit question
Solved by:
Eleanor Berger
Solved:
Last query:
Last reply:
Revision history for this message
Best Eleanor Berger (intellectronica) said :
#1

For basic doc and some code snippets, see http://webpy.infogami.com/templetor

To display your page from inside a web.py app, just do:

    homepage = template.Template(open("homepage.tmpl").read())
    print homepage()

Alternatively, you can use the render object to access all of your templates:

    render = web.render('templates/') # Render can be a global object - it will optionally cache templates

    print render.my_template() # the method name corresponds to the name of a template file