Giter Site home page Giter Site logo

frost-nzcr4 / django-rest-framework-xml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jpadilla/django-rest-framework-xml

0.0 1.0 0.0 463 KB

XML support for Django REST Framework

Home Page: http://jpadilla.github.io/django-rest-framework-xml

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

django-rest-framework-xml's Introduction

REST Framework XML

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.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.

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>[email protected]</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.

django-rest-framework-xml's People

Contributors

brandoncazander avatar faulkner avatar helenst avatar jayvdb avatar jpadilla avatar kevin-brown avatar philall avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.