當前位置: 首頁>>代碼示例>>Python>>正文


Python environment.Template方法代碼示例

本文整理匯總了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" 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:19,代碼來源:jinja2_tests.py

示例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) 
開發者ID:apache,項目名稱:incubator-ariatosca,代碼行數:21,代碼來源:config.py

示例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) 
開發者ID:cloudify-cosmo,項目名稱:cloudify-cli,代碼行數:16,代碼來源:init.py

示例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() 
開發者ID:holoviz,項目名稱:panel,代碼行數:17,代碼來源:base.py


注:本文中的jinja2.environment.Template方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。