def render_string(self, template_name, **kwargs):
#template_path = self.get_template_path()
#if not template_path:
#frame = sys._getframe(0)
#web_file = frame.f_code.co_filename
#while frame.f_code.co_filename == web_file:
#frame = frame.f_back
#template_path = os.path.dirname(frame.f_code.co_filename)
#with RequestHandler._template_loader_lock:
#if template_path not in RequestHandler._template_loaders:
#loader = self.create_template_loader(template_path)
#RequestHandler._template_loaders[template_path] = loader
#else:
#loader = RequestHandler._template_loaders[template_path]
#t = loader.load(template_name)
#namespace = self.get_template_namespace()
#namespace.update(kwargs)
#return t.generate(**namespace)
with io.open(template_name, mode='r',encoding='UTF-8') as f:
html = f.read()
template_strings = Template(html)
return template_strings.render(context=Context(dict_=kwargs))
评论列表
文章目录