Render templates using Jinja async mode

Closes #628
This commit is contained in:
Simon Willison 2019-11-14 15:14:22 -08:00 committed by GitHub
commit 8c642f04e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 15 deletions

View file

@ -583,7 +583,9 @@ class Datasette:
),
]
)
self.jinja_env = Environment(loader=template_loader, autoescape=True)
self.jinja_env = Environment(
loader=template_loader, autoescape=True, enable_async=True
)
self.jinja_env.filters["escape_css_string"] = escape_css_string
self.jinja_env.filters["quote_plus"] = lambda u: urllib.parse.quote_plus(u)
self.jinja_env.filters["escape_sqlite"] = escape_sqlite
@ -730,5 +732,5 @@ class DatasetteRouter(AsgiRouter):
else:
template = self.ds.jinja_env.select_template(templates)
await asgi_send_html(
send, template.render(info), status=status, headers=headers
send, await template.render_async(info), status=status, headers=headers
)

View file

@ -139,7 +139,7 @@ class BaseView(AsgiView):
extra_template_vars.update(extra_vars)
return Response.html(
template.render(
await template.render_async(
{
**context,
**{