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

Python mustache.render函数代码示例

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

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



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

示例1: render

    def render(self, template_name, context={}, index=None):
        """
        Given a template name, pick a template and render it with the provided
        context.

        :param template_name: the name of a template group.

        :param context: dictionary representing values to be rendered

        :param index: optional, the specific index in the collection of
            templates

        :raises NotImplementedError: if no template can be found identified by
            template_name

        :return:
        """
        if template_name not in self.templates:
            raise NotImplementedError("Template not found: %s" % template_name)
        template_functions = self.templates.get(template_name)
        if index is None:
            index = random.randrange(len(template_functions))
        else:
            index %= len(template_functions)
        return mustache.render(template_functions[index], context)
开发者ID:Alphacodeclub,项目名称:mycroft-core,代码行数:25,代码来源:__init__.py


示例2: test

	def test(self):
		template = testData['template']
		partials = testData.has_key('partials') and testData['partials'] or {}
		expected = testData['expected']
		data	 = testData['data']

		# Convert code strings to functions.
		new_data = {}
		for key, val in data.iteritems():
			if isinstance(val, dict) and val.get('__tag__') == 'code':
				val = eval(val['python'])
			new_data[key] = val

		actual = render(template, new_data, partials)

		message = """%s

  Template: \"""%s\"""

  Expected: %s
  Actual:   %s

  Expected: \"""%s\"""
  Actual:   \"""%s\"""
  """ % (description, template, repr(expected), repr(actual), expected, actual)

		self.assertEquals(actual, expected, message)
开发者ID:fredericksilva,项目名称:python-mustache,代码行数:27,代码来源:test_spec.py


示例3: test_non_strings

	def test_non_strings(self):
		template = "{{#stats}}({{key}} & {{value}}){{/stats}}"
		stats = []
		stats.append({'key': 123, 'value': ['something']})
		stats.append({'key': u"chris", 'value': 0.900})

		ret = mustache.render(template, { 'stats': stats })
		self.assertEquals(ret, """(123 & ['something'])(chris & 0.9)""")
开发者ID:peterldowns,项目名称:python-mustache,代码行数:8,代码来源:test_mustache.py


示例4: render_template

def render_template(name, context):
    template = open(os.path.join(TEMPLATES_ROOT, name), 'r').read()

    partials = {
        'header': open(os.path.join(TEMPLATES_ROOT, 'header.html')).read(),
        'footer': open(os.path.join(TEMPLATES_ROOT, 'footer.html')).read(),
    }

    return mustache.render(template, context, partials=partials)
开发者ID:waylybaye,项目名称:solog,代码行数:9,代码来源:views.py


示例5: __spec_test

 def __spec_test(self, test_suite):
     with open(self.PATH.format(test_suite), 'r') as fp:
         suite = json.loads(fp.read())
     tests = suite['tests']
     for test in tests:
         template = mustache.build(test['template'], test.get('partials'))
         result = mustache.render(template, test['data'])
         msg = '{}: {} != {}'.format(test['desc'], repr(str(test['expected'])), repr(str(result)))
         self.assertEqual(result, test['expected'], msg)
开发者ID:mylokin,项目名称:mustache,代码行数:9,代码来源:test_mustache.py


示例6: test_render_zero

	def test_render_zero(self):
		template = 'My value is {{value}}.'
		ret = mustache.render(template, { 'value': 0 })
		self.assertEquals(ret, 'My value is 0.')
开发者ID:peterldowns,项目名称:python-mustache,代码行数:4,代码来源:test_mustache.py


示例7: test_ignores_misses

	def test_ignores_misses(self):
		template = "I think {{name}} wants a {{thing}}, right {{name}}?"
		ret = mustache.render(template, { 'name': 'Jon' })
		self.assertEquals(ret, "I think Jon wants a , right Jon?")
开发者ID:peterldowns,项目名称:python-mustache,代码行数:4,代码来源:test_mustache.py


示例8: test_interpolation_19

 def test_interpolation_19(self):
     template = u'"{{a.b.c.name}}" == ""'
     template = mustache.build(template, partials=None)
     context = {u'a': {u'b': {}}, u'c': {u'name': u'Jim'}}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'"" == ""')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py


示例9: test_interpolation_13

 def test_interpolation_13(self):
     template = u'I ({{&cannot}}) be seen!'
     template = mustache.build(template, partials=None)
     context = {}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'I () be seen!')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py


示例10: test_sections

	def test_sections(self):
		template = """<ul>{{#users}}<li>{{name}}</li>{{/users}}</ul>"""

		context = { 'users': [ {'name': 'Chris'}, {'name': 'Tom'}, {'name': 'PJ'} ] }
		ret = mustache.render(template, context)
		self.assertEquals(ret, """<ul><li>Chris</li><li>Tom</li><li>PJ</li></ul>""")
开发者ID:peterldowns,项目名称:python-mustache,代码行数:6,代码来源:test_mustache.py


示例11: test_unicode

	def test_unicode(self):
		template = 'Name: {{name}}; Age: {{age}}'
		ret = mustache.render(template, { 'name': u'Henri Poincaré',
			'age': 156 })
		self.assertEquals(ret, u'Name: Henri Poincaré; Age: 156')
开发者ID:peterldowns,项目名称:python-mustache,代码行数:5,代码来源:test_mustache.py


示例12: test_true_sections_are_shown

	def test_true_sections_are_shown(self):
		template = "Ready {{#set}}set{{/set}} go!"
		ret = mustache.render(template, { 'set': True })
		self.assertEquals(ret, "Ready set go!")
开发者ID:peterldowns,项目名称:python-mustache,代码行数:4,代码来源:test_mustache.py


示例13: test_partials_10

 def test_partials_10(self):
     template = u'|{{> partial }}|'
     template = mustache.build(template, partials={u'partial': u'[]'})
     context = {u'boolean': True}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'|[]|')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py


示例14: test_partials_9

 def test_partials_9(self):
     template = u'\\\n {{>partial}}\n/\n'
     template = mustache.build(template, partials={u'partial': u'|\n{{{content}}}\n|\n'})
     context = {u'content': u'<\n->'}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'\\\n |\n <\n->\n |\n/\n')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py


示例15: test_interpolation_29

 def test_interpolation_29(self):
     template = u'|{{& string }}|'
     template = mustache.build(template, partials=None)
     context = {u'string': u'---'}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'|---|')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py


示例16: test_partials_8

 def test_partials_8(self):
     template = u'>\n  {{>partial}}'
     template = mustache.build(template, partials={u'partial': u'>\n>'})
     context = {}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'>\n  >\n  >')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py


示例17: test_partials_0

 def test_partials_0(self):
     template = u'"{{>text}}"'
     template = mustache.build(template, partials={u'text': u'from partial'})
     context = {}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'"from partial"')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py


示例18: test_interpolation_20

 def test_interpolation_20(self):
     template = u'"{{#a}}{{b.c.d.e.name}}{{/a}}" == "Phil"'
     template = mustache.build(template, partials=None)
     context = {u'a': {u'b': {u'c': {u'd': {u'e': {u'name': u'Phil'}}}}}, u'b': {u'c': {u'd': {u'e': {u'name': u'Wrong'}}}}}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'"Phil" == "Phil"')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py


示例19: test_comments

	def test_comments(self):
		template = "What {{! the }} what?"
		ret = mustache.render(template, {})
		self.assertEquals(ret, "What  what?")
开发者ID:peterldowns,项目名称:python-mustache,代码行数:4,代码来源:test_mustache.py


示例20: test_inverted_1

 def test_inverted_1(self):
     template = u'"{{^boolean}}This should not be rendered.{{/boolean}}"'
     template = mustache.build(template, partials=None)
     context = {u'boolean': True}
     rendered = mustache.render(template, context)
     self.assertEqual(rendered, u'""')
开发者ID:mylokin,项目名称:mustache,代码行数:6,代码来源:test_mustache.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python mutagen.File类代码示例发布时间:2022-05-27
下一篇:
Python mustache.build函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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