本文整理匯總了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()