mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
render_template() returns rendered string, not Response
This commit is contained in:
parent
e05777d74f
commit
5d1b424cfc
2 changed files with 12 additions and 13 deletions
|
|
@ -591,13 +591,7 @@ class Datasette:
|
||||||
},
|
},
|
||||||
**extra_template_vars,
|
**extra_template_vars,
|
||||||
}
|
}
|
||||||
if request.args.get("_context") and self.config("template_debug"):
|
return await template.render_async(template_context)
|
||||||
return Response.html(
|
|
||||||
"<pre>{}</pre>".format(
|
|
||||||
escape(json.dumps(template_context, default=repr, indent=4))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return Response.html(await template.render_async(template_context))
|
|
||||||
|
|
||||||
def _asset_urls(self, key, template, context):
|
def _asset_urls(self, key, template, context):
|
||||||
# Flatten list-of-lists from plugins:
|
# Flatten list-of-lists from plugins:
|
||||||
|
|
|
||||||
|
|
@ -74,17 +74,22 @@ class BaseView(AsgiView):
|
||||||
|
|
||||||
async def render(self, templates, request, context):
|
async def render(self, templates, request, context):
|
||||||
template = self.ds.jinja_env.select_template(templates)
|
template = self.ds.jinja_env.select_template(templates)
|
||||||
return await self.ds.render_template(
|
template_context = {
|
||||||
template,
|
|
||||||
{
|
|
||||||
**context,
|
**context,
|
||||||
**{
|
**{
|
||||||
"database_url": self.database_url,
|
"database_url": self.database_url,
|
||||||
"database_color": self.database_color,
|
"database_color": self.database_color,
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
request=request,
|
if request and request.args.get("_context") and self.config("template_debug"):
|
||||||
)
|
return Response.html(
|
||||||
|
"<pre>{}</pre>".format(
|
||||||
|
escape(json.dumps(template_context, default=repr, indent=4))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return Response.html(await self.ds.render_template(
|
||||||
|
template, template_context, request=request
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
class DataView(BaseView):
|
class DataView(BaseView):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue