jpadilla / django-rest-framework-xml

XML support for Django REST Framework
http://jpadilla.github.io/django-rest-framework-xml
BSD 3-Clause "New" or "Revised" License
86 stars 59 forks source link

Update to support content-type text/xml. #29

Closed oddcc closed 5 years ago

muhammedabad commented 5 years ago

I have also had the need to support text/xml where a 3rd party provider cannot change their content type value.

Instead of replicating the whole class, I simply just extended it and overwrote the media_type value.

from rest_framework_xml.parsers import XMLParser

class TextXMLParser(XMLParser):
    media_type = "text/xml"

All that's needed is to add the custom parser to DRF settings:

REST_FRAMEWORK = {
    'DEFAULT_PARSER_CLASSES': [
        'rest_framework.parsers.JSONParser',
        'myapp.parsers.text_xml.TextXMLParser'
    ]
...

And that seems to work perfectly.

jpadilla commented 5 years ago

@oddcc thanks for the PR. @muhammedabad's comment shows a suggested workaround, which is also what I would recommend.