MCPcopy Create free account
hub / github.com/datapane/datapane / template

Function template

python-client/src/datapane/_vendor/bottle.py:4213–4237  ·  view source on GitHub ↗

Get a rendered template as a string iterator. You can use a name, a filename or a template string as first parameter. Template rendering arguments can be passed as dictionaries or directly (as keyword arguments).

(*args, **kwargs)

Source from the content-addressed store, hash-verified

4211
4212
4213def template(*args, **kwargs):
4214 """
4215 Get a rendered template as a string iterator.
4216 You can use a name, a filename or a template string as first parameter.
4217 Template rendering arguments can be passed as dictionaries
4218 or directly (as keyword arguments).
4219 """
4220 tpl = args[0] if args else None
4221 for dictarg in args[1:]:
4222 kwargs.update(dictarg)
4223 adapter = kwargs.pop('template_adapter', SimpleTemplate)
4224 lookup = kwargs.pop('template_lookup', TEMPLATE_PATH)
4225 tplid = (id(lookup), tpl)
4226 if tplid not in TEMPLATES or DEBUG:
4227 settings = kwargs.pop('template_settings', {})
4228 if isinstance(tpl, adapter):
4229 TEMPLATES[tplid] = tpl
4230 if settings: TEMPLATES[tplid].prepare(**settings)
4231 elif "\n" in tpl or "{" in tpl or "%" in tpl or '$' in tpl:
4232 TEMPLATES[tplid] = adapter(source=tpl, lookup=lookup, **settings)
4233 else:
4234 TEMPLATES[tplid] = adapter(name=tpl, lookup=lookup, **settings)
4235 if not TEMPLATES[tplid]:
4236 abort(500, 'Template (%s) not found' % tpl)
4237 return TEMPLATES[tplid].render(kwargs)
4238
4239
4240mako_template = functools.partial(template, template_adapter=MakoTemplate)

Callers 2

default_error_handlerMethod · 0.85
wrapperFunction · 0.85

Calls 4

abortFunction · 0.85
updateMethod · 0.80
prepareMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected