Добавление прокладок в функцию xml prettify в python django
я начинающий питонец, я написал xml-функцию для придания xml красивого вида с помощью xml.dom.minidom вот эта функция :
def payload_xml_prettified(self, instance): """Функция для отображения красивой версии наших xml-данных"""" import xml.dom.minidom
dom = xml.dom.minidom.parseString(instance.payload_xml)
xml_pretty_str = dom.toprettyxml()
return xml_pretty_str
payload_xml_prettified.short_description = "payload_xml"
it works fine but without a padding the reult like this :
:
<?xml version="1.0" ?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
how can i update the code to show the xml on the right way with padding to shown like this : <?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies
и спасибо за поддержку