YAML support for Django REST Framework
Full documentation for the project is available at http://qu4tro.github.io/drf-yaml.
YAML support for the Django REST Framework, forked from https://github.com/jpadilla/django-rest-framework-yaml.
- Python (3.8, 3.9, 3.10, 3.11)
- Django (3.2, 4.*)
Install using pip
...
$ pip install drf-yaml
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,)
---
-
email: [email protected]
is_staff: true
url: "http://127.0.0.1:8000/users/1/"
username: jpadilla
Full documentation for the project is available at http://qu4tro.github.io/drf-yaml.