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)
| 839 | self._write_buffer.append(chunk) |
| 840 | |
| 841 | def render(self, template_name: str, **kwargs: Any) -> "Future[None]": |
| 842 | """Renders the template with the given arguments as the response. |
| 843 | |
| 844 | ``render()`` calls ``finish()``, so no other output methods can be called |
| 845 | after it. |
| 846 | |
| 847 | Returns a `.Future` with the same semantics as the one returned by `finish`. |
| 848 | Awaiting this `.Future` is optional. |
| 849 | |
| 850 | .. versionchanged:: 5.1 |
| 851 | |
| 852 | Now returns a `.Future` instead of ``None``. |
| 853 | """ |
| 854 | if self._finished: |
| 855 | raise RuntimeError("Cannot render() after finish()") |
| 856 | html = self.render_string(template_name, **kwargs) |
| 857 | |
| 858 | # Insert the additional JS and CSS added by the modules on the page |
| 859 | js_embed = [] |
| 860 | js_files = [] |
| 861 | css_embed = [] |
| 862 | css_files = [] |
| 863 | html_heads = [] |
| 864 | html_bodies = [] |
| 865 | for module in getattr(self, "_active_modules", {}).values(): |
| 866 | embed_part = module.embedded_javascript() |
| 867 | if embed_part: |
| 868 | js_embed.append(utf8(embed_part)) |
| 869 | file_part = module.javascript_files() |
| 870 | if file_part: |
| 871 | if isinstance(file_part, (unicode_type, bytes)): |
| 872 | js_files.append(_unicode(file_part)) |
| 873 | else: |
| 874 | js_files.extend(file_part) |
| 875 | embed_part = module.embedded_css() |
| 876 | if embed_part: |
| 877 | css_embed.append(utf8(embed_part)) |
| 878 | file_part = module.css_files() |
| 879 | if file_part: |
| 880 | if isinstance(file_part, (unicode_type, bytes)): |
| 881 | css_files.append(_unicode(file_part)) |
| 882 | else: |
| 883 | css_files.extend(file_part) |
| 884 | head_part = module.html_head() |
| 885 | if head_part: |
| 886 | html_heads.append(utf8(head_part)) |
| 887 | body_part = module.html_body() |
| 888 | if body_part: |
| 889 | html_bodies.append(utf8(body_part)) |
| 890 | |
| 891 | if js_files: |
| 892 | # Maintain order of JavaScript files given by modules |
| 893 | js = self.render_linked_js(js_files) |
| 894 | sloc = html.rindex(b"</body>") |
| 895 | html = html[:sloc] + utf8(js) + b"\n" + html[sloc:] |
| 896 | if js_embed: |
| 897 | js_bytes = self.render_embed_js(js_embed) |
| 898 | sloc = html.rindex(b"</body>") |
nothing calls this directly
no test coverage detected