[Django]-What does 'serializer.initial_data' mean?

6👍

When passing data to a serializer instance, the unmodified data will be made available as .initial_data. If the data keyword argument is not passed then the .initial_data attribute will not exist.

serializer = MyFooSerializer(data={'foo':'bar'})
print(serializer.initial_data) # this will print {'foo':'bar'}

The request.data returns the parsed content of the request body.

👤JPG

3👍

Requests.data contains the data that comes in from the frontend. Arguably, you should leave requests.data alone and use a serializer to convert said data into more complex types. The use cases for serializers are pretty vast ranging, but the most common is translation of data into database model instances.

👤Fydo

Leave a comment