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


Python templates.Template类代码示例

本文整理汇总了Python中werkzeug.templates.Template的典型用法代码示例。如果您正苦于以下问题:Python Template类的具体用法?Python Template怎么用?Python Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_multidict

def test_multidict():
    """Template multidict behavior"""
    t = Template('$a|$b')
    assert t.render(MultiDict(dict(
        a=[1, 2],
        b=2
    ))) == '1|2'
开发者ID:marchon,项目名称:checkinmapper,代码行数:7,代码来源:test_templates.py

示例2: test_code

def test_code():
    """Template code block"""
    t = Template('''<%py
        a = 'A'
        b = 'B'
    %>$a$b''')
    assert t.render() == 'AB'
开发者ID:marchon,项目名称:checkinmapper,代码行数:7,代码来源:test_templates.py

示例3: test_if

def test_if():
    """Template if condition"""
    t = Template('<% if idx == 1 %>ONE<% elif idx == 2 %>TWO<% elif '
                 'idx == 3 %>THREE<% else %>OMGWTF<% endif %>')
    assert t.render(idx=0) == 'OMGWTF'
    assert t.render(idx=1) == 'ONE'
    assert t.render(idx=2) == 'TWO'
    assert t.render(idx=3) == 'THREE'
开发者ID:marchon,项目名称:checkinmapper,代码行数:8,代码来源:test_templates.py

示例4: render_template

 def render_template(self, template=None):
     if template is None:
         template = self.__class__.identifier + '.html'
     context = dict(self.__dict__)
     context.update(url_for=self.url_for, self=self)
     body_tmpl = Template.from_file(path.join(templates, template))
     layout_tmpl = Template.from_file(path.join(templates, 'layout.html'))
     context['body'] = body_tmpl.render(context)
     return layout_tmpl.render(context)
开发者ID:0x19,项目名称:werkzeug,代码行数:9,代码来源:application.py

示例5: get_template

 def get_template(self, name):
     """Get a template from a given name."""
     filename = path.join(self.search_path, *[p for p in name.split('/')
                                              if p and p[0] != '.'])
     if not path.exists(filename):
         raise TemplateNotFound(name)
     return Template.from_file(filename, self.encoding)
开发者ID:garyyeap,项目名称:zoe-robot,代码行数:7,代码来源:kickstart.py

示例6: generate

 def generate(self, rsp, **kwargs):
     global settings
     kwargs['cfg_line'] = lambda s, d=None: s + ' = ' + repr(settings.get(s, d))
     for filename in ('launch.wsgi', 'app.py', 'settings.py', 'manage.py'):
         with open(in_cwd(filename), 'w') as f:
             # Template strips off trailing whitespace...
             f.write(Template.from_file(in_skeld(filename + '.tmpl')).render(**kwargs) + '\n')
     os.chmod(in_cwd('manage.py'), 0755)
开发者ID:diazona,项目名称:Modulo,代码行数:8,代码来源:__init__.py

示例7: test_interpolation

def test_interpolation():
    """Template variable interpolation"""
    t = Template('\n'.join([
        '$string',
        '${", ".join(string.upper().split(" AND "))}',
        '$string.replace("foo", "bar").title()',
        '${string}s',
        '${1, 2, 3}',
        '$string[0:3][::-1]'
    ]))
    assert t.render(string='foo and blah').splitlines() == [
        'foo and blah',
        'FOO, BLAH',
        'Bar And Blah',
        'foo and blahs',
        '(1, 2, 3)',
        'oof'
    ]
开发者ID:marchon,项目名称:checkinmapper,代码行数:18,代码来源:test_templates.py

示例8: test_from_file_with_filename

def test_from_file_with_filename():
    """Template from_file where file parameter is a filename"""
    fd, filename = tempfile.mkstemp()
    try:
        os.write(fd, "Hello ${you}!")
    finally:
        os.close(fd)
    try:
        t = Template.from_file(filename)
        assert t.render(you="World") == "Hello World!"
    finally:
        os.unlink(filename)
开发者ID:strogo,项目名称:werkzeug,代码行数:12,代码来源:test_templates.py

示例9: test_break

def test_break():
    """Template brake statement"""
    t = Template('<% for i in xrange(5) %><%py break %>$i<% endfor %>')
    assert t.render() == ''
开发者ID:marchon,项目名称:checkinmapper,代码行数:4,代码来源:test_templates.py

示例10: test_nl_trim

def test_nl_trim():
    """Template newline trimming"""
    t = Template('<% if 1 %>1<% endif %>\n2')
    assert t.render() == '12'
开发者ID:marchon,项目名称:checkinmapper,代码行数:4,代码来源:test_templates.py

示例11: test_unicode

def test_unicode():
    """Template unicode modes"""
    t = Template(u'öäü$szlig')
    assert t.render(szlig='ß') == u'öäüß'
    t = Template(u'öäü$szlig', unicode_mode=False, charset='iso-8859-15')
    assert t.render(szlig='\xdf') == '\xf6\xe4\xfc\xdf'
开发者ID:marchon,项目名称:checkinmapper,代码行数:6,代码来源:test_templates.py

示例12: test_undefined

def test_undefined():
    """Template undefined behavior"""
    t = Template('<% for item in seq %>$item<% endfor %>$missing')
    assert t.render() == ''
开发者ID:marchon,项目名称:checkinmapper,代码行数:4,代码来源:test_templates.py

示例13: test_from_file_with_fileobject

def test_from_file_with_fileobject():
    """Template from_file where file parameter is a file object"""
    t = Template.from_file(sio.StringIO("Hello ${you}!"))
    assert t.render(you="World") == "Hello World!"
开发者ID:strogo,项目名称:werkzeug,代码行数:4,代码来源:test_templates.py

示例14: test_print

def test_print():
    """Template print helper"""
    t = Template('1 <%py print "2", %>3')
    t.render() == '1 2 3'
开发者ID:marchon,项目名称:checkinmapper,代码行数:4,代码来源:test_templates.py

示例15: test_for

def test_for():
    """Template for loop"""
    t = Template('<% for i in range(10) %>[$i]<% endfor %>')
    assert t.render() == ''.join(['[%s]' % i for i in xrange(10)])
开发者ID:marchon,项目名称:checkinmapper,代码行数:4,代码来源:test_templates.py


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