如何更改根元素和列表项元素的名称?(django-rest-framework) [英] How to change the root element and list-item elements name? (django-rest-framework)

查看:46
本文介绍了如何更改根元素和列表项元素的名称?(django-rest-framework)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是django-rest-framework的新手,我有像

I am new to django-rest-framework i have working sample like

<root>
    <list-item>worrier1</list-item>
    <list-item>worrier2</list-item>
<root>

我需要的是

<Hero>
    <worrier1>worrier1</worrier1>
    <worrier2>worrier2</worrier2>
<Hero>

推荐答案

这些都是硬编码的值,因此,您获得的唯一机会是通过覆盖 XMLRenderer 创建自定义渲染器(实际上,这样做会几乎是整个类),然后在您的视图中使用该自定义渲染器.

Those are hardcoded values, so the only chance you get, is to create custom renderer by overriding the XMLRenderer (which in effect would be pretty much the whole class) and use that custom renderer in your view.

这篇关于如何更改根元素和列表项元素的名称?(django-rest-framework)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆