Karrigell/Insert dynamic values in a template

From Wikibooks, open books for an open world
< Karrigell
Jump to: navigation, search

The templating system uses Python string formatting

Create a template called page.tmpl :

<html>
<head>
<title>{title}</title>
</head>
<body>
Hello {name}
</body>
</html>

then edit index.py and add this function :

def bar(name):
    return Template('page.tmpl',title='template test',name=name)

Enter http://localhost/index.py/bar?name=Joe to see how the templating engine replaced the placeholders {title} and {name} by the values passed to the function Template