import time
context={
'now':int(time.time()),
'strftime':time.strftime } # Note there are no brackets () after strftime
# This means we are passing in a function,
# not the result of a function.
self.response.write(jinja2.render_template('sometemplate.html', **context))
然后可以在sometemplate.html中使用:
<html>
<body>
<p>The time is \{\{ strftime('%H:%M%:%S',now) }}, and 5 seconds ago it was \{\{ strftime('%H:%M%:%S',now-5) }}.
</body>
</html>