I have two questions about Django Rest Framework response message
1.
When use generics.ListCreateAPIView
or RetrieveDestroyAPIView
, usually return a resource
For example ,call /map/ with POST Method The result will like a object :
{
"x_axis": "23",
"y_axis": "25",
"map_id": 1,
}
I want to know can I edit this message to custom like below?
{"Success":"msg blablabla"}
2.
When I use serializers.ValidationError
,
I can write my custom message
if I use raise serializers.ValidationError("map_id does not exist")
The response message will be
{"map_id":["map_id does not exist"]}
Can I edit this part to custom like below?
{"FAIL":"map_id does not exist"}
I want to know this because front-end don't want this format, They like :
{"Success":"msg blablabla"}
{"Fail":"msg blablabla"}
{"USERNAME_DUPLICATE":1001}
{"FIELD_REQUIRED":1002}
So they can be more convenient to tell user the operate error cause ?