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)
| 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. |
no test coverage detected