Quantcast
Channel: User Christoffer - Stack Overflow
Viewing all articles
Browse latest Browse all 45

Answer by Christoffer for django-rest-framework - autogenerate form in browsable API?

$
0
0

Create a serialiser class that fits the form input fields you want and set it on your APIView like so;

class MyView(APIView):
    serializer_class = MySerializer  # Used for the form in the browsable api

That works just perfectly.

Example of a serializer class based on a model:

from rest_framework import serializers

class MySerializer(serializers.ModelSerializer):
    class Meta:
        model = MyModel

Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>