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)
| 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 |