DRF-XML如何添加前缀和特定格式的呈现

时间:2019-03-20 10:20:58

标签: django xml django-rest-framework rss

我正在尝试创建一个链接,该链接将通过序列化器呈现来自模型的提要,以实现Facebook动态添加。 我正在使用Django REST Framework进行XML渲染, 但是我得到的输出是

<root>
<list-item>
    <id>286</id>
    <title>Dog Bowl In Blue</title>
    <description>
       Solid plastic Dog Bowl in marine blue colo
    </description>
    <price>400.00</price>
    <category_name/>
    <cook>Mrs John</cook>
    <thumbnail>
        https://ee5b36248ba0_thumb.jpg
    </thumbnail>
    <is_always_available>False</is_always_available>
    <preparation_time>6.0</preparation_time>
</list-item>
</root>

但是我需要这样渲染

<?xml version="1.0"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <channel>
        <title>Test Store</title>
        <link>http://www.example.com</link>
        <description>An example item from the feed</description>
        <item>
            <g:id>DB_1</g:id>
            <g:title>Dog Bowl In Blue</g:title>
            <g:description>Solid plastic Dog Bowl in marine blue color</g:description>
            <g:link>http://www.example.com/bowls/db-1.html</g:link>
            <g:image_link>http://images.example.com/DB_1.png</g:image_link>
            <g:brand>Example</g:brand>
            <g:condition>new</g:condition>
            <g:availability>in stock</g:availability>
            <g:price>9.99 GBP</g:price>
            <g:shipping>
                <g:country>UK</g:country>
                <g:service>Standard</g:service>
                <g:price>4.95 GBP</g:price>
            </g:shipping>
            <g:google_product_category>Animals &gt; Pet Supplies</g:google_product_category>
            <g:custom_label_0>Made in Waterford, IE</g:custom_label_0>
        </item>
    </channel>
</rss>

有人可以帮我吗?

0 个答案:

没有答案