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.0.0.tar.gz (3.5 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.0.0-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for djangorestframework-xml-1.0.0.tar.gz
Algorithm Hash digest
SHA256 079add645233bf530f0757587a393d090a5aac7e4439ab272034c900556fa7e6
MD5 99649eaeeaf768a5c2fcf3b28b4f7a7e
BLAKE2b-256 95515e1cc4c87431cd9d364379a5164d0ee5d0334c6d14464c08b7495a9b0349

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for djangorestframework_xml-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cbe2e0dbc1ddb8bd8893f1b802c8e3191ccbfd05b02ac43ca542331e78b4c2b5
MD5 0c993f0871a13ee9b089120316def71a
BLAKE2b-256 15a1ab486f009e8afcc68bef407ea69b974dfdcc71b5124972d16055d098de21

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