本文整理汇总了Python中jinja2.environment.Template方法的典型用法代码示例。如果您正苦于以下问题:Python environment.Template方法的具体用法?Python environment.Template怎么用?Python environment.Template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.environment
的用法示例。
在下文中一共展示了environment.Template方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_string
# 需要导入模块: from jinja2 import environment [as 别名]
# 或者: from jinja2.environment import Template [as 别名]
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"
示例2: create_config
# 需要导入模块: from jinja2 import environment [as 别名]
# 或者: from jinja2.environment import Template [as 别名]
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)
示例3: set_config
# 需要导入模块: from jinja2 import environment [as 别名]
# 或者: from jinja2.environment import Template [as 别名]
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)
示例4: __init__
# 需要导入模块: from jinja2 import environment [as 别名]
# 或者: from jinja2.environment import Template [as 别名]
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()