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


Python Template.render方法代码示例

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


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

示例1: test_let_directive_scope

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
    def test_let_directive_scope ( self ):
        '''test let directive's scope'''
        
        vars = dict ( 
            message = 'hello, from breve',
            title = my_name ( ),
            do_fail = False
        )

        # don't fail - use variable in scope
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise

        # do fail - try to use the variable out of scope
        vars [ 'do_fail' ] = True
        t = Template ( html, root = template_root ( ) )
        self.failUnlessRaises (
            NameError,
            t.render, 'index', vars, namespace = 'v'
        )
开发者ID:stuffonfire,项目名称:breve,代码行数:28,代码来源:templates.py

示例2: test_custom_renderer

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
    def test_custom_renderer ( self ):
        '''custom renderer'''

        def render_row ( tag, data ):
            T = html
            tag.clear ( )
            return tag [
                [ T.td [ _i ] for _i in data ]
            ]
        register_global ( 'render_row', render_row )

        vars = dict ( 
            title = my_name ( ),
            my_data = [
                range ( 5 ),
                range ( 5, 10 ),
                range ( 10, 15 )
            ]
        )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
开发者ID:stuffonfire,项目名称:breve,代码行数:29,代码来源:templates.py

示例3: render

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
 def render(value, system):
     value.update(system)
     fragment = value.pop('breve_fragment', self.fragment)
     template = Template(self.tags, xmlns=self.xmlns,
                         doctype=self.doctype)
     return template.render(info.name, vars=value, fragment=fragment,
                            loader=self.loader)
开发者ID:momyc,项目名称:pyramid-breve,代码行数:9,代码来源:renderer.py

示例4: test_encoding

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
    def test_encoding ( self ):
        '''encoding comments'''

        vars = dict ( 
            title = my_name ( )
        )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'wrong', vars, namespace = 'v' )
        expected = expected_output ( )
        self.assertNotEqual ( actual, expected )
        actual = t.render ( 'correct', vars, namespace = 'v' )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
开发者ID:BenoitZugmeyer,项目名称:breve,代码行数:18,代码来源:templates.py

示例5: test_render_parameters

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_render_parameters():
    """test render-time parameters"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    args = {
        'tidy': True,
        'debug': True,
        'namespace': 'v',
        'extension': '.breve'
    }
    t = Template(html, root=template_root())
    t.render('index', params, **args)
    actual = [getattr(t, k, 'not_set') for k in sorted(args)]
    expected = [v for k, v in sorted(args.items())]
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:19,代码来源:test_templates.py

示例6: test_render_parameters

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
 def test_render_parameters ( self ):
     '''test render-time parameters'''
     
     vars = dict ( 
         message = 'hello, from breve',
         title = my_name ( )
     )
     args = { 
         'tidy': True, 
         'debug': True, 
         'namespace': 'v', 
         'extension': '.breve'
     }
     t = Template ( html, root = template_root ( ) )
     t.render ( 'index', vars, **args )
     for k, v in args.items ( ):
         self.failUnless ( getattr ( t, k ) == v )
开发者ID:stuffonfire,项目名称:breve,代码行数:19,代码来源:templates.py

示例7: test_encoding

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_encoding():
    """encoding comments"""
    params = dict(
        title=my_name()
    )
    t = Template(html, root=template_root())
    expected = expected_output()
    actual = t.render('correct', params, namespace='v')
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:11,代码来源:test_templates.py

示例8: test_simple_template

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_simple_template():
    """simple template"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:12,代码来源:test_templates.py

示例9: test_nested_include

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_nested_include():
    """nested include() directives"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:12,代码来源:test_templates.py

示例10: test_loop_include

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_loop_include():
    """looping over include() with listcomp"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:12,代码来源:test_templates.py

示例11: test_assign_scope

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_assign_scope():
    """test assign directive's scope"""
    params = dict(
        message='hello, from breve',
        title=my_name()
    )
    # don't fail - use variable in scope
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:13,代码来源:test_templates.py

示例12: test_register_global

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_register_global():
    """register_global() function"""
    params = dict(
        title=my_name()
    )
    register_global('global_message', 'This is a global variable')

    _test_name = my_name()
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:14,代码来源:test_templates.py

示例13: test_stacks_template

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_stacks_template():
    """test stacks in template"""
    params = dict(
        title=my_name(),
        message='hello, from breve'
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
    # stack should be empty when we finish
    assert not get_stacks()
开发者ID:katakumpo,项目名称:breve4py3,代码行数:14,代码来源:test_templates.py

示例14: test_macros_inside_inherits

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def test_macros_inside_inherits():
    """test macros inside inherits(): scope issues"""
    # note: I'm not convinced this is the desired behaviour, but
    # it's *compatible* behaviour.
    params = dict(
        title=my_name(),
        message='Hello, from breve'
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
开发者ID:katakumpo,项目名称:breve4py3,代码行数:14,代码来源:test_templates.py

示例15: render

# 需要导入模块: from breve import Template [as 别名]
# 或者: from breve.Template import render [as 别名]
def render(template_name, tmpl_params=None, loader=None, fragment=False):
    if tmpl_params is None:
        tmpl_params = {}

    g = pylons_globals()
    tmpl_params.update(g)

    try:
        opts = g['app_globals'].breve_opts
    except AttributeError:
        opts = {}

    t = Template(tags, **opts)
    return t.render(template_name, params=tmpl_params, loader=loader, fragment=fragment)
开发者ID:katakumpo,项目名称:breve4py3,代码行数:16,代码来源:pylons_adapter.py


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