YAML support for Django REST Framework
Project description
REST Framework YAML
YAML support for Django REST Framework
Full documentation for the project is available at http://qu4tro.github.io/django-rest-framework-yaml.
Overview
YAML support for the Django REST Framework, forked from https://github.com/jpadilla/django-rest-framework-yaml.
Requirements
- Python (3.8, 3.9, 3.10, 3.11)
- Django (3.2, 4.*)
Installation
Install using pip
...
$ pip install drf-yaml
Example
REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': (
'drf_yaml.parsers.YAMLParser',
),
'DEFAULT_RENDERER_CLASSES': (
'drf_yaml.renderers.YAMLRenderer',
),
}
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 drf_yaml.parsers import YAMLParser
from drf_yaml.renderers import YAMLRenderer
# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('url', 'username', 'email', 'is_staff')
# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
parser_classes = (YAMLParser,)
renderer_classes = (YAMLRenderer,)
Sample output
---
-
email: jpadilla@example.com
is_staff: true
url: "http://127.0.0.1:8000/users/1/"
username: jpadilla
Documentation & Support
Full documentation for the project is available at http://qu4tro.github.io/django-rest-framework-yaml.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
drf_yaml-3.0.0.tar.gz
(5.5 kB
view hashes)