Renders the template with the given arguments as the response. ``render()`` calls ``finish()``, so no other output methods can be called after it. Returns a `.Future` with the same semantics as the one returned by `finish`. Awaiting this `.Future` is optional.
(self, template_name: str, **kwargs: Any)
| 1008 | self._write_buffer.append(chunk) |
| 1009 | |
| 1010 | def render(self, template_name: str, **kwargs: Any) -> "Future[None]": |
| 1011 | """Renders the template with the given arguments as the response. |
| 1012 | |
| 1013 | ``render()`` calls ``finish()``, so no other output methods can be called |
| 1014 | after it. |
| 1015 | |
| 1016 | Returns a `.Future` with the same semantics as the one returned by `finish`. |
| 1017 | Awaiting this `.Future` is optional. |
| 1018 | |
| 1019 | .. versionchanged:: 5.1 |
| 1020 | |
| 1021 | Now returns a `.Future` instead of ``None``. |
| 1022 | """ |
| 1023 | if self._finished: |
| 1024 | raise RuntimeError("Cannot render() after finish()") |
| 1025 | html = self.render_string(template_name, **kwargs) |
| 1026 | |
| 1027 | # Insert the additional JS and CSS added by the modules on the page |
| 1028 | js_embed = [] |
| 1029 | js_files = [] |
| 1030 | css_embed = [] |
| 1031 | css_files = [] |
| 1032 | html_heads = [] |
| 1033 | html_bodies = [] |
| 1034 | for module in getattr(self, "_active_modules", {}).values(): |
| 1035 | embed_part = module.embedded_javascript() |
| 1036 | if embed_part: |
| 1037 | js_embed.append(utf8(embed_part)) |
| 1038 | file_part = module.javascript_files() |
| 1039 | if file_part: |
| 1040 | if isinstance(file_part, (unicode_type, bytes)): |
| 1041 | js_files.append(_unicode(file_part)) |
| 1042 | else: |
| 1043 | js_files.extend(file_part) |
| 1044 | embed_part = module.embedded_css() |
| 1045 | if embed_part: |
| 1046 | css_embed.append(utf8(embed_part)) |
| 1047 | file_part = module.css_files() |
| 1048 | if file_part: |
| 1049 | if isinstance(file_part, (unicode_type, bytes)): |
| 1050 | css_files.append(_unicode(file_part)) |
| 1051 | else: |
| 1052 | css_files.extend(file_part) |
| 1053 | head_part = module.html_head() |
| 1054 | if head_part: |
| 1055 | html_heads.append(utf8(head_part)) |
| 1056 | body_part = module.html_body() |
| 1057 | if body_part: |
| 1058 | html_bodies.append(utf8(body_part)) |
| 1059 | |
| 1060 | if js_files: |
| 1061 | # Maintain order of JavaScript files given by modules |
| 1062 | js = self.render_linked_js(js_files) |
| 1063 | sloc = html.rindex(b"</body>") |
| 1064 | html = html[:sloc] + utf8(js) + b"\n" + html[sloc:] |
| 1065 | if js_embed: |
| 1066 | js_bytes = self.render_embed_js(js_embed) |
| 1067 | sloc = html.rindex(b"</body>") |
nothing calls this directly
no test coverage detected