Skip to main content

build-status-image pypi-version

XML support for Django REST Framework

Full documentation for the project is available at http://jpadilla.github.io/django-rest-framework-xml.

Overview

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.

Requirements

  • Python (2.7, 3.3, 3.4)

  • Django (1.6, 1.7)

  • Django REST Framework (2.4.3, 2.4.4, 3.0-beta)

Installation

Install using pip

$ pip install djangorestframework-xml

Example

REST_FRAMEWORK = {
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_xml.parsers.XMLParser',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_xml.renderers.XMLRenderer',
    ),
}

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"?>
<root>
    <list-item>
        <url>http://127.0.0.1:8000/users/1/.xml</url>
        <username>jpadilla</username>
        <email>jpadilla@example.com</email>
        <is_staff>True</is_staff>
    </list-item>
</root>

Documentation & Support

Full documentation for the project is available at http://jpadilla.github.io/django-rest-framework-xml.

You may also want to follow the author on Twitter.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangorestframework-xml-1.2.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djangorestframework_xml-1.2.0-py2.py3-none-any.whl (4.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file djangorestframework-xml-1.2.0.tar.gz.

File metadata

File hashes

Hashes for djangorestframework-xml-1.2.0.tar.gz
Algorithm Hash digest
SHA256 0b91ba3f4fc68531f57c11b79cdb59063c19a15d25f0eee799212f252ab8a3ee
MD5 0e7605f4884dfb5ea5a317cbede999ab
BLAKE2b-256 1519b65262059e1f524212001f5659df3e85d05f481eccc9759b1f11ee9b0114

See more details on using hashes here.

File details

Details for the file djangorestframework_xml-1.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for djangorestframework_xml-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 795e2688446b751b7eaf63ea3d188cae38950e428b03f5dd114147ed83819b03
MD5 34321461ed29644c2c1f76fd3f6e361b
BLAKE2b-256 ac55c347fb2cc56012ba764e0ba55e9bec814fbea8008a38c00f94965cf8fcf0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page