djangorestframework-xml


Namedjangorestframework-xml JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/jpadilla/django-rest-framework-xml
SummaryXML support for Django REST Framework
upload_time2020-04-12 22:38:43
maintainer
docs_urlNone
authorJosé Padilla
requires_python>=3.5
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # REST Framework XML

[![build-status-image]][github-action]
[![pypi-version]][pypi]

**XML support for Django REST Framework**

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

## Overview

XML support extracted as a third party package directly from the official Django REST Framework implementation. It requires the [defusedxml][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 3.5+
* Django 2.2+
* Django REST Framework 3.11+

## Installation

Install using `pip`...

```bash
$ pip install djangorestframework-xml
```

## Example

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

```python
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
<?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][docs].

You may also want to follow the [author][jpadilla] on Twitter.


[build-status-image]: https://github.com/jpadilla/django-rest-framework-xml/workflows/CI/badge.svg
[github-action]: https://github.com/jpadilla/django-rest-framework-xml/actions?query=workflow%3ACI
[pypi-version]: https://img.shields.io/pypi/v/djangorestframework-xml.svg
[pypi]: https://pypi.python.org/pypi/djangorestframework-xml
[defusedxml]: https://pypi.python.org/pypi/defusedxml
[docs]: http://jpadilla.github.io/django-rest-framework-xml
[jpadilla]: https://twitter.com/jpadilla_



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jpadilla/django-rest-framework-xml",
    "name": "djangorestframework-xml",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "",
    "author": "Jos\u00e9 Padilla",
    "author_email": "hello@jpadilla.com",
    "download_url": "https://files.pythonhosted.org/packages/45/74/b75939a779fddef1d3e108991f7edb199e6240f23b6aef64f3a222e1b4dd/djangorestframework-xml-2.0.0.tar.gz",
    "platform": "",
    "description": "# REST Framework XML\n\n[![build-status-image]][github-action]\n[![pypi-version]][pypi]\n\n**XML support for Django REST Framework**\n\nFull documentation for the project is available at [http://jpadilla.github.io/django-rest-framework-xml][docs].\n\n## Overview\n\nXML support extracted as a third party package directly from the official Django REST Framework implementation. It requires the [defusedxml][defusedxml] package only because it safeguards against some security issues that were discovered.\n\n**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.\n\n## Requirements\n\n* Python 3.5+\n* Django 2.2+\n* Django REST Framework 3.11+\n\n## Installation\n\nInstall using `pip`...\n\n```bash\n$ pip install djangorestframework-xml\n```\n\n## Example\n\n```python\nREST_FRAMEWORK = {\n    'DEFAULT_PARSER_CLASSES': (\n        'rest_framework_xml.parsers.XMLParser',\n    ),\n    'DEFAULT_RENDERER_CLASSES': (\n        'rest_framework_xml.renderers.XMLRenderer',\n    ),\n}\n```\n\nYou can also set the renderer and parser used for an individual view, or viewset, using the APIView class based views.\n\n```python\nfrom rest_framework import routers, serializers, viewsets\nfrom rest_framework_xml.parsers import XMLParser\nfrom rest_framework_xml.renderers import XMLRenderer\n\n\nclass UserSerializer(serializers.HyperlinkedModelSerializer):\n    class Meta:\n        model = User\n        fields = ('url', 'username', 'email', 'is_staff')\n\n\nclass UserViewSet(viewsets.ModelViewSet):\n    queryset = User.objects.all()\n    serializer_class = UserSerializer\n    parser_classes = (XMLParser,)\n    renderer_classes = (XMLRenderer,)\n```\n\n### Sample output\n\n```xml\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n    <list-item>\n        <url>http://127.0.0.1:8000/users/1/.xml</url>\n        <username>jpadilla</username>\n        <email>jpadilla@example.com</email>\n        <is_staff>True</is_staff>\n    </list-item>\n</root>\n```\n\n## Documentation & Support\n\nFull documentation for the project is available at [http://jpadilla.github.io/django-rest-framework-xml][docs].\n\nYou may also want to follow the [author][jpadilla] on Twitter.\n\n\n[build-status-image]: https://github.com/jpadilla/django-rest-framework-xml/workflows/CI/badge.svg\n[github-action]: https://github.com/jpadilla/django-rest-framework-xml/actions?query=workflow%3ACI\n[pypi-version]: https://img.shields.io/pypi/v/djangorestframework-xml.svg\n[pypi]: https://pypi.python.org/pypi/djangorestframework-xml\n[defusedxml]: https://pypi.python.org/pypi/defusedxml\n[docs]: http://jpadilla.github.io/django-rest-framework-xml\n[jpadilla]: https://twitter.com/jpadilla_\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "XML support for Django REST Framework",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/jpadilla/django-rest-framework-xml"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f7465485e0ceae183b9348cd080cc69126e498a95bcd5d37df84a598bf94bbd",
                "md5": "6eb6bb1d7ec2bf88981ef6aa8c5e00b5",
                "sha256": "975955fbb0d49ac44a90bdeb33b7923d95b79884d283f983e116c80a936ef4d0"
            },
            "downloads": -1,
            "filename": "djangorestframework_xml-2.0.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6eb6bb1d7ec2bf88981ef6aa8c5e00b5",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.5",
            "size": 6046,
            "upload_time": "2020-04-12T22:38:43",
            "upload_time_iso_8601": "2020-04-12T22:38:43.087572Z",
            "url": "https://files.pythonhosted.org/packages/0f/74/65485e0ceae183b9348cd080cc69126e498a95bcd5d37df84a598bf94bbd/djangorestframework_xml-2.0.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4574b75939a779fddef1d3e108991f7edb199e6240f23b6aef64f3a222e1b4dd",
                "md5": "9742297428c1af5eb1a1352e546115be",
                "sha256": "35f6c811d0ab8c8466b26db234e16a2ed32d76381715257aebf4c7be2c202ca1"
            },
            "downloads": -1,
            "filename": "djangorestframework-xml-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9742297428c1af5eb1a1352e546115be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 5412,
            "upload_time": "2020-04-12T22:38:43",
            "upload_time_iso_8601": "2020-04-12T22:38:43.862048Z",
            "url": "https://files.pythonhosted.org/packages/45/74/b75939a779fddef1d3e108991f7edb199e6240f23b6aef64f3a222e1b4dd/djangorestframework-xml-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-04-12 22:38:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jpadilla",
    "github_project": "django-rest-framework-xml",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "djangorestframework-xml"
}
        
Elapsed time: 0.39393s