当前位置: 首页>>代码示例>>Python>>正文


Python Environment.get_template方法代码示例

本文整理汇总了Python中ambari_jinja2.Environment.get_template方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.get_template方法的具体用法?Python Environment.get_template怎么用?Python Environment.get_template使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ambari_jinja2.Environment的用法示例。


在下文中一共展示了Environment.get_template方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_correct_prefix_loader_name

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
 def test_correct_prefix_loader_name(self):
     env = Environment(loader=PrefixLoader({
         'foo':  DictLoader({})
     }))
     try:
         env.get_template('foo/bar.html')
     except TemplateNotFound, e:
         assert e.name == 'foo/bar.html'
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:10,代码来源:regression.py

示例2: test_preserve_blocks

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
 def test_preserve_blocks(self):
     env = Environment(loader=DictLoader({
         'a': '{% if false %}{% block x %}A{% endblock %}{% endif %}{{ self.x() }}',
         'b': '{% extends "a" %}{% block x %}B{{ super() }}{% endblock %}'
     }))
     tmpl = env.get_template('b')
     assert tmpl.render() == 'BA'
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:9,代码来源:inheritance.py

示例3: test_autoescape_autoselect

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
 def test_autoescape_autoselect(self):
     def select_autoescape(name):
         if name is None or '.' not in name:
             return False
         return name.endswith('.html')
     env = Environment(autoescape=select_autoescape,
                       loader=DictLoader({
         'test.txt':     '{{ foo }}',
         'test.html':    '{{ foo }}'
     }))
     t = env.get_template('test.txt')
     assert t.render(foo='<foo>') == '<foo>'
     t = env.get_template('test.html')
     assert t.render(foo='<foo>') == '&lt;foo&gt;'
     t = env.from_string('{{ foo }}')
     assert t.render(foo='<foo>') == '<foo>'
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:18,代码来源:api.py

示例4: test_dynamic_inheritance

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
 def test_dynamic_inheritance(self):
     env = Environment(loader=DictLoader({
         'master1': 'MASTER1{% block x %}{% endblock %}',
         'master2': 'MASTER2{% block x %}{% endblock %}',
         'child': '{% extends master %}{% block x %}CHILD{% endblock %}'
     }))
     tmpl = env.get_template('child')
     for m in range(1, 3):
         assert tmpl.render(master='master%d' % m) == 'MASTER%dCHILD' % m
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:11,代码来源:inheritance.py

示例5: test_multi_inheritance

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
 def test_multi_inheritance(self):
     env = Environment(loader=DictLoader({
         'master1': 'MASTER1{% block x %}{% endblock %}',
         'master2': 'MASTER2{% block x %}{% endblock %}',
         'child': '''{% if master %}{% extends master %}{% else %}{% extends
                     'master1' %}{% endif %}{% block x %}CHILD{% endblock %}'''
     }))
     tmpl = env.get_template('child')
     assert tmpl.render(master='master2') == 'MASTER2CHILD'
     assert tmpl.render(master='master1') == 'MASTER1CHILD'
     assert tmpl.render() == 'MASTER1CHILD'
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:13,代码来源:inheritance.py

示例6: test_super

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
 def test_super(self):
     env = Environment(loader=DictLoader({
         'a': '{% block intro %}INTRO{% endblock %}|'
              'BEFORE|{% block data %}INNER{% endblock %}|AFTER',
         'b': '{% extends "a" %}{% block data %}({{ '
              'super() }}){% endblock %}',
         'c': '{% extends "b" %}{% block intro %}--{{ '
              'super() }}--{% endblock %}\n{% block data '
              '%}[{{ super() }}]{% endblock %}'
     }))
     tmpl = env.get_template('c')
     assert tmpl.render() == '--INTRO--|BEFORE|[(INNER)]|AFTER'
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:14,代码来源:inheritance.py

示例7: Template

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
 class Template(Source):
   def __init__(self, name, extra_imports=[], **kwargs):
     """
     @param kwargs: Additional variables passed to template
     """
     super(Template, self).__init__(name)
     params = self.env.config.params
     variables = checked_unite(params, kwargs)
     self.imports_dict = dict((module.__name__, module) for module in extra_imports)
     self.context = variables.copy() if variables else {}
     if not hasattr(self, 'template_env'):
       self.template_env = JinjaEnvironment(loader=TemplateLoader(self.env),
                                       autoescape=False, undefined=StrictUndefined, trim_blocks=True)
       
     self.template = self.template_env.get_template(self.name)     
   
   def get_content(self):
     default_variables = { 'env':self.env, 'repr':repr, 'str':str, 'bool':bool }
     variables = checked_unite(default_variables, self.imports_dict)
     self.context.update(variables)
     
     rendered = self.template.render(self.context)
     return rendered + "\n" if not rendered.endswith('\n') else rendered
开发者ID:fanzhidongyzby,项目名称:ambari,代码行数:25,代码来源:source.py

示例8: Environment

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
from ambari_jinja2 import Environment
from ambari_jinja2.loaders import DictLoader


env = Environment(loader=DictLoader({
'a': '''[A[{% block body %}{% endblock %}]]''',
'b': '''{% extends 'a' %}{% block body %}[B]{% endblock %}''',
'c': '''{% extends 'b' %}{% block body %}###{{ super() }}###{% endblock %}'''
}))


print env.get_template('c').render()
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:14,代码来源:inheritance.py

示例9: test_context_include_with_overrides

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
 def test_context_include_with_overrides(self):
     env = Environment(loader=DictLoader(dict(
         main="{% for item in [1, 2, 3] %}{% include 'item' %}{% endfor %}",
         item="{{ item }}"
     )))
     assert env.get_template("main").render() == "123"
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:8,代码来源:imports.py

示例10: Environment

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
from ambari_jinja2 import Environment
from ambari_jinja2.loaders import FileSystemLoader

env = Environment(loader=FileSystemLoader('templates'))

tmpl = env.get_template('broken.html')
print tmpl.render(seq=[3, 2, 4, 5, 3, 2, 0, 2, 1])
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:9,代码来源:debugger.py

示例11: Environment

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
from ambari_jinja2.loaders import DictLoader

env = Environment(
    loader=DictLoader(
        {
            "child.html": u"""\
{% extends master_layout or 'master.html' %}
{% include helpers = 'helpers.html' %}
{% macro get_the_answer() %}42{% endmacro %}
{% title = 'Hello World' %}
{% block body %}
    {{ get_the_answer() }}
    {{ helpers.conspirate() }}
{% endblock %}
""",
            "master.html": u"""\
<!doctype html>
<title>{{ title }}</title>
{% block body %}{% endblock %}
""",
            "helpers.html": u"""\
{% macro conspirate() %}23{% endmacro %}
""",
        }
    )
)


tmpl = env.get_template("child.html")
print tmpl.render()
开发者ID:fanzhidongyzby,项目名称:ambari,代码行数:32,代码来源:test.py

示例12: map

# 需要导入模块: from ambari_jinja2 import Environment [as 别名]
# 或者: from ambari_jinja2.Environment import get_template [as 别名]
users = map(User, [u"John Doe", u"Jane Doe", u"Peter Somewhat"])
articles = map(Article, range(20))
navigation = [
    ("index", "Index"),
    ("about", "About"),
    ("foo?bar=1", "Foo with Bar"),
    ("foo?bar=2&s=x", "Foo with X"),
    ("blah", "Blub Blah"),
    ("hehe", "Haha"),
] * 5

context = dict(users=users, articles=articles, page_navigation=navigation)


jinja_template = jinja_env.get_template("index.html")
mako_template = mako_lookup.get_template("index.html")
genshi_template = genshi_loader.load("index.html")


def test_jinja():
    jinja_template.render(context)


def test_mako():
    mako_template.render_unicode(**context)


from djangoext import django_loader, DjangoContext

开发者ID:fanzhidongyzby,项目名称:ambari,代码行数:30,代码来源:rwbench.py


注:本文中的ambari_jinja2.Environment.get_template方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。