Skip to content
XML support for Django REST Framework
Branch: master
Clone or download
jpadilla Merge pull request #38 from jayvdb/patch-1
Set LICENSE to BSD-3-Clause
Latest commit 71c2f88 Apr 13, 2019

REST Framework XML

build-status-image pypi-version

XML support for Django REST Framework

Full documentation for the project is available at


XML support extracted as a third party package directly from the official Django REST Framework implementation. It requires the defusedxml package only because it safeguards against some security issues that were discovered.

Note: XML output provided is an ad-hoc format that isn't formally described. If you have specific XML requirements you'll need to write your own XML parsers/renderers in order to fully control the representation.


  • Python (2.7, 3.4, 3.5, 3.6)
  • Django (1.8 - 1.11, 2.0 - 2.1)
  • Django REST Framework (2.4, 3.0 - 3.9)

This project is tested on the combinations of Python and Django that are supported by each version of Django REST Framework.


Install using pip...

$ pip install djangorestframework-xml



You can also set the renderer and parser used for an individual view, or viewset, using the APIView class based views.

from rest_framework import routers, serializers, viewsets
from rest_framework_xml.parsers import XMLParser
from rest_framework_xml.renderers import XMLRenderer

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')

class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    parser_classes = (XMLParser,)
    renderer_classes = (XMLRenderer,)

Sample output

<?xml version="1.0" encoding="utf-8"?>

Documentation & Support

Full documentation for the project is available at

You may also want to follow the author on Twitter.

You can’t perform that action at this time.