'how to get validated data from serializers to views in django rest framework

I am returning some data from def create method in seriaizers.py file I want to acccess that data in views.py I dont know how to get it. serilizers.py

def create(self, validated_data):
      //returning something
      return validated_data

views.py

if serializer.is_valid():
     serializer.save()
     //I want to return that validated_data here so how to get it here here
      Response(validated_data)


Solution 1:[1]

To get the validated data, use serializer.validated_data. See the Deserializing Objects section of the manual.

Also, I want to point out a potential footgun here: you're supposed to return a model instance, from the create() method, rather than the validated data.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick ODell