9👍
I Got the answer from Tom Christie:
serializer_class
by itself isn’t enough – the view needs to implement get_serializer, see: https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas.py#L570
So in My case, adding this works well:
def get_serializer(self):
return ActivateCustomerSerializer()
0👍
EDIT: I forgot to answer regarding the input parameters. I believe that would be based on the serializer. Have you tried specifying your serializer_class
?
With DRF’s inbuilt documentation generator, you’d want to put your docstrings on the class level and include the request method as such:
class ActivateCustomerView(APIView):
"""
post:
View dedicated to activating a pre-recorded customer
# Should I add some parameters here?
# if you have a get request
get:
# your docs for the get handler
"""
permission_classes = (AllowAny,)
def post(self, request):
serializer = ActivateCustomerSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
# ...
- Encoding gives "'ascii' codec can't encode character … ordinal not in range(128)"
- Django AttributeError: 'DatabaseOperations' object has no attribute 'select'
- Django saving json value to database/model
- In Django how do I notify a parent when a child is saved in a foreign key relationship?
Source:stackexchange.com