Python jinja2.environment.Template() Examples
The following are 4
code examples of jinja2.environment.Template().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
jinja2.environment
, or try the search function
.
Example #1
Source File: jinja2_tests.py From apm-agent-python with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_from_string(instrument, elasticapm_client): elasticapm_client.begin_transaction("transaction.test") template = Template("<html></html") template.render() elasticapm_client.end_transaction("test") transactions = elasticapm_client.events[TRANSACTION] spans = elasticapm_client.spans_for_transaction(transactions[0]) expected_signatures = {"<template>"} assert {t["name"] for t in spans} == expected_signatures assert spans[0]["name"] == "<template>" assert spans[0]["type"] == "template" assert spans[0]["subtype"] == "jinja2" assert spans[0]["action"] == "render"
Example #2
Source File: config.py From incubator-ariatosca with Apache License 2.0 | 6 votes |
def create_config(cls, workdir): config_path = os.path.join(workdir, CONFIG_FILE_NAME) if not os.path.isfile(config_path): config_template = pkg_resources.resource_string( __package__, 'config_template.yaml') default_values = { 'log_path': os.path.join(workdir, 'cli.log'), 'enable_colors': True } template = Template(config_template) rendered = template.render(**default_values) with open(config_path, 'w') as f: f.write(rendered) f.write(os.linesep) return cls(config_path)
Example #3
Source File: init.py From cloudify-cli with Apache License 2.0 | 5 votes |
def set_config(enable_colors=False): cli_config = pkg_resources.resource_string( cloudify_cli.__name__, 'config/config_template.yaml').decode('utf-8') enable_colors = str(enable_colors).lower() template = Template(cli_config) rendered = template.render( log_path=DEFAULT_LOG_FILE, enable_colors=enable_colors ) with open(config.CLOUDIFY_CONFIG_PATH, 'a') as f: f.write(rendered) f.write(os.linesep)
Example #4
Source File: base.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, template=None, items=None, nb_template=None, **params): super(BaseTemplate, self).__init__(**params) if isinstance(template, string_types): self._code = template template = _Template(template) else: self._code = None self.template = template if isinstance(nb_template, string_types): nb_template = _Template(nb_template) self.nb_template = nb_template or template self._render_items = {} self._render_variables = {} self._server = None self._layout = self._build_layout()