Expose extra_template_vars in _contex=1, refs #693

This commit is contained in:
Simon Willison 2020-04-05 11:49:15 -07:00
commit e89b0ef2f9
3 changed files with 14 additions and 11 deletions

View file

@ -14,6 +14,7 @@ from pathlib import Path
import click
from markupsafe import Markup
import jinja2
from jinja2 import ChoiceLoader, Environment, FileSystemLoader, PrefixLoader, escape
from jinja2.environment import Template
import uvicorn
@ -612,6 +613,11 @@ class Datasette:
},
**extra_template_vars,
}
if request and request.args.get("_context") and self.config("template_debug"):
return "<pre>{}</pre>".format(
jinja2.escape(json.dumps(template_context, default=repr, indent=4))
)
return await template.render_async(template_context)
def _asset_urls(self, key, template, context):