Reputation: 11
def post(self,request):
serializer=NameSerializers(data=request.data)
if(serializer.is_valid):
name=serializer.data.get('name')
msg='hello {} Wish you happy New Year'.format(name)
return Response({'msg':msg})
return Response(serializer.errors,status=400)
My questions are:
data=request.data
getting the data the client app has been sending in JSON?serializer.is_valid
an in-built function of serializer class to check the data we have received is valid data or not? serializer.data.get('name')
doing?Upvotes: 0
Views: 100
Reputation: 903
request.data
is basically data sent in the request body from the client.serializer.is_valid()
, yes, it is a function to check data received from the request, you can pass serializer.is_valid(raise_exception=True)
to raise an exception in case of invalid data received.serializer.data
is a python dictionary which is being saved in the model, so .get('var_name')
is actually accessing the value from the dictionary.Hope this helps :) Happy Coding
Upvotes: 1