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

Method render

python/python3/tornado/web.py:850–923  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

render_stringMethod · 0.95
render_linked_jsMethod · 0.95
render_embed_jsMethod · 0.95
render_linked_cssMethod · 0.95
render_embed_cssMethod · 0.95
finishMethod · 0.95
utf8Function · 0.90
joinMethod · 0.80
embedded_javascriptMethod · 0.45
appendMethod · 0.45
javascript_filesMethod · 0.45
embedded_cssMethod · 0.45

Tested by

no test coverage detected