lepture
2011-03-28 17:19:36 +08:00
这样的思路不知可否?
from jinja2 import Environment, FileSystemLoader
class render_jinja:
"""
modified from web.contrib.template
"""
def __init__(self, *arg, **kwargs):
extensions = kwargs.pop('extensions',[])
filters = kwargs.pop('filters', {})
gvars = kwargs.pop('gvars', {}) # global vars
self._lookup = Environment(loader=FileSystemLoader(*arg, **kwargs), extensions=extensions)
self._lookup.globals.update(gvars)
self._lookup.filters.update(filters)
def render_template(self, name, **kwargs):
t = self._lookup.get_template(name)
return t.render(**kwargs)
然后给定值到gvars