I am new to django-rest-framework i have working sample like
<root>
<list-item>worrier1</list-item>
<list-item>worrier2</list-item>
<root>
What i need is
<Hero>
<worrier1>worrier1</worrier1>
<worrier2>worrier2</worrier2>
<Hero>
I am new to django-rest-framework i have working sample like
<root>
<list-item>worrier1</list-item>
<list-item>worrier2</list-item>
<root>
What i need is
<Hero>
<worrier1>worrier1</worrier1>
<worrier2>worrier2</worrier2>
<Hero>
If you wish to do this generically you don't need to override too much of the class:
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.I don't think you need to go so far as to create a whole subclass, I was able to do it by overriding the instance variables after creating the instance and before running render, see below:
Hope that helps anyone else who stumbles by
In the spirit of being helpful to anyone else who searches for this... Below is how you can subclass the XMLRenderer and override the root tag (previously "root") and item tags (previously "list-item") to whatever you like.
For anyone who wants to edit the actual package, you can go to your Python folder, site-packages, rest_framework_xml, and edit renderers.py
When you get there, you can edit:
item_tag_name = 'list-item'
and change this toitem_tag_name = 'item'
Note: By doing this method, you are overriding the actual class. For my project, it does not matter, but if you intend to use the xml library for another Django project, just keep this in mind.