• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python templates.Template类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_while

def test_while():
    """Template while loop"""
    t = Template('<%py idx = 0 %><% while idx < 10 %>x<%py idx += 1 %><% endwhile %>')
    assert t.render() == 'x' * 10
开发者ID:marchon,项目名称:checkinmapper,代码行数:4,代码来源:test_templates.py


示例17: test_substitute

def test_substitute():
    """Templer rendering responds to substitute as well"""
    t = Template('<% if a %>1<% endif %>\n2')
    assert t.render(a=1) == t.substitute(a=1)
开发者ID:marchon,项目名称:checkinmapper,代码行数:4,代码来源:test_templates.py


示例18: generate

 def generate(self, rsp, **kwargs):
     template_data = self.req.environ.copy()
     template_data.update(kwargs)
     rsp.data = Template.from_file(self.filename).render(template_data)
开发者ID:diazona,项目名称:Modulo,代码行数:4,代码来源:minitmpl.py


示例19: get_template

def get_template(filename):
    return Template.from_file(join(dirname(__file__), 'templates', filename))
开发者ID:Pluckyduck,项目名称:eve,代码行数:2,代码来源:utils.py


示例20: test_continue

def test_continue():
    """Template continue statement"""
    t = Template('<% for i in xrange(10) %><% if i % 2 == 0 %>'
                 '<%py continue %><% endif %>$i<% endfor %>')
    assert t.render() == '13579'
开发者ID:marchon,项目名称:checkinmapper,代码行数:5,代码来源:test_templates.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test.create_environ函数代码示例发布时间:2022-05-26
下一篇:
Python serving.run_with_reloader函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap