當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。