this is what i use:
===================
from jinja2 import Environment, FunctionLoader , TemplateNotFound
from google.appengine.api import memcache
import os,logging
VERSION = os.environ['CURRENT_VERSION_ID']
logging.warn ("COLD START")
def jinja2_template_loader(templatename):
templatepath = os.path.abspath(os.curdir+'/
template/'+templatename)
template = memcache.get(templatepath+VERSION)
logging.debug( "......INSIDE JINJA....")
if template is None:
try:
logging.debug( "......READ....")
template = file(templatepath).read()
memcache.set(templatepath+VERSION,template,time=500)
except:
template = None
return template
SERVER = os.environ.get('SERVER_SOFTWARE','').lower()
if SERVER.startswith('devel'):
logging.debug("...DEVEL JINJA....")
load_this = Environment(cache_size=0,loader = FunctionLoader
(jinja2_template_loader))
else:
load_this = Environment(loader= FunctionLoader
(jinja2_template_loader))
def render(template_name,context):
template = load_this.get_template(template_name)
content = template.render(context)
return content
=========================
if your app handlers are cached (ie via "if __name__ == '__main__':main
()") this should be imported only once per server instance. It also
caches templates both in memcache (for 8 minutes) and in instance
memory
(in case of local testing, templates are not cached in memory, so you
can make changes and see the changes immediately)
HTH
Peter