本文整理汇总了Python中djangorestframework.renderers.XMLRenderer.render方法的典型用法代码示例。如果您正苦于以下问题:Python XMLRenderer.render方法的具体用法?Python XMLRenderer.render怎么用?Python XMLRenderer.render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类djangorestframework.renderers.XMLRenderer
的用法示例。
在下文中一共展示了XMLRenderer.render方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render_decimal
# 需要导入模块: from djangorestframework.renderers import XMLRenderer [as 别名]
# 或者: from djangorestframework.renderers.XMLRenderer import render [as 别名]
def test_render_decimal(self):
"""
Test XML rendering.
"""
renderer = XMLRenderer(None)
content = renderer.render({'field': Decimal('111.2')}, 'application/xml')
self.assertXMLContains(content, '<field>111.2</field>')
示例2: test_render_none
# 需要导入模块: from djangorestframework.renderers import XMLRenderer [as 别名]
# 或者: from djangorestframework.renderers.XMLRenderer import render [as 别名]
def test_render_none(self):
"""
Test XML rendering.
"""
renderer = XMLRenderer(None)
content = renderer.render({'field': None}, 'application/xml')
self.assertXMLContains(content, '<field></field>')
示例3: test_render_datetime
# 需要导入模块: from djangorestframework.renderers import XMLRenderer [as 别名]
# 或者: from djangorestframework.renderers.XMLRenderer import render [as 别名]
def test_render_datetime(self):
"""
Test XML rendering.
"""
renderer = XMLRenderer(None)
content = renderer.render({"field": datetime.datetime(2011, 12, 25, 12, 45, 00)}, "application/xml")
self.assertXMLContains(content, "<field>2011-12-25 12:45:00</field>")
示例4: test_render_complex_data
# 需要导入模块: from djangorestframework.renderers import XMLRenderer [as 别名]
# 或者: from djangorestframework.renderers.XMLRenderer import render [as 别名]
def test_render_complex_data(self):
"""
Test XML rendering.
"""
renderer = XMLRenderer(None)
content = renderer.render(self._complex_data, 'application/xml')
self.assertXMLContains(content, '<sub_name>first</sub_name>')
self.assertXMLContains(content, '<sub_name>second</sub_name>')
示例5: test_render_and_parse_complex_data
# 需要导入模块: from djangorestframework.renderers import XMLRenderer [as 别名]
# 或者: from djangorestframework.renderers.XMLRenderer import render [as 别名]
def test_render_and_parse_complex_data(self):
"""
Test XML rendering.
"""
renderer = XMLRenderer(None)
content = StringIO(renderer.render(self._complex_data, 'application/xml'))
parser = XMLParser(None)
complex_data_out, dummy = parser.parse(content)
error_msg = "complex data differs!IN:\n %s \n\n OUT:\n %s" % (repr(self._complex_data), repr(complex_data_out))
self.assertEqual(self._complex_data, complex_data_out, error_msg)