MCPcopy
hub / github.com/pallets/jinja / render_async

Method render_async

src/jinja2/environment.py:1297–1318  ·  view source on GitHub ↗

This works similar to :meth:`render` but returns a coroutine that when awaited returns the entire rendered template string. This requires the async feature to be enabled. Example usage:: await template.render_async(knights='that say nih; asynchronously')

(self, *args: t.Any, **kwargs: t.Any)

Source from the content-addressed store, hash-verified

1295 self.environment.handle_exception()
1296
1297 async def render_async(self, *args: t.Any, **kwargs: t.Any) -> str:
1298 """This works similar to :meth:`render` but returns a coroutine
1299 that when awaited returns the entire rendered template string. This
1300 requires the async feature to be enabled.
1301
1302 Example usage::
1303
1304 await template.render_async(knights='that say nih; asynchronously')
1305 """
1306 if not self.environment.is_async:
1307 raise RuntimeError(
1308 "The environment was not created with async mode enabled."
1309 )
1310
1311 ctx = self.new_context(dict(*args, **kwargs))
1312
1313 try:
1314 return self.environment.concat( # type: ignore
1315 [n async for n in self.root_render_func(ctx)] # type: ignore
1316 )
1317 except Exception:
1318 return self.environment.handle_exception()
1319
1320 def stream(self, *args: t.Any, **kwargs: t.Any) -> "TemplateStream":
1321 """Works exactly like :meth:`generate` but returns a

Callers 4

renderMethod · 0.95
_testFunction · 0.95
funcFunction · 0.45
testFunction · 0.45

Calls 2

new_contextMethod · 0.95
handle_exceptionMethod · 0.80

Tested by 3

_testFunction · 0.76
funcFunction · 0.36
testFunction · 0.36