From f3fa6ecf61861d142c8e0592b01143a2f9a3f1ff Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 19 Jun 2026 23:38:50 -0700 Subject: [PATCH] Render error pages using datasette.render_template() Avoids risk of important variables not being present. --- datasette/handle_exception.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/datasette/handle_exception.py b/datasette/handle_exception.py index 96398a4c..91031b3d 100644 --- a/datasette/handle_exception.py +++ b/datasette/handle_exception.py @@ -59,16 +59,12 @@ def handle_exception(datasette, request, exception): if request.path.split("?")[0].endswith(".json"): return Response.json(info, status=status, headers=headers) else: - environment = datasette.get_jinja_environment(request) - template = environment.select_template(templates) return Response.html( - await template.render_async( - dict( - info, - urls=datasette.urls, - app_css_hash=datasette.app_css_hash(), - menu_links=lambda: [], - ) + await datasette.render_template( + templates, + info, + request=request, + view_name="error", ), status=status, headers=headers,