MCPcopy Create free account
hub / github.com/EasyIME/PIME / render_string

Method render_string

python/python3/tornado/web.py:990–1014  ·  view source on GitHub ↗

Generate the given template with the given arguments. We return the generated byte string (in utf8). To generate and write a template as a response, use render() above.

(self, template_name: str, **kwargs: Any)

Source from the content-addressed store, hash-verified

988 return b'<style type="text/css">\n' + b"\n".join(css_embed) + b"\n</style>"
989
990 def render_string(self, template_name: str, **kwargs: Any) -> bytes:
991 """Generate the given template with the given arguments.
992
993 We return the generated byte string (in utf8). To generate and
994 write a template as a response, use render() above.
995 """
996 # If no template_path is specified, use the path of the calling file
997 template_path = self.get_template_path()
998 if not template_path:
999 frame = sys._getframe(0)
1000 web_file = frame.f_code.co_filename
1001 while frame.f_code.co_filename == web_file and frame.f_back is not None:
1002 frame = frame.f_back
1003 assert frame.f_code.co_filename is not None
1004 template_path = os.path.dirname(frame.f_code.co_filename)
1005 with RequestHandler._template_loader_lock:
1006 if template_path not in RequestHandler._template_loaders:
1007 loader = self.create_template_loader(template_path)
1008 RequestHandler._template_loaders[template_path] = loader
1009 else:
1010 loader = RequestHandler._template_loaders[template_path]
1011 t = loader.load(template_name)
1012 namespace = self.get_template_namespace()
1013 namespace.update(kwargs)
1014 return t.generate(**namespace)
1015
1016 def get_template_namespace(self) -> Dict[str, Any]:
1017 """Returns a dictionary to be used as the default template namespace.

Callers 1

renderMethod · 0.95

Calls 6

get_template_pathMethod · 0.95
loadMethod · 0.45
updateMethod · 0.45
generateMethod · 0.45

Tested by

no test coverage detected