我想要什么?
成功:
{
"data": {
"id": 123,
"name": "Django"
}
}
错误(序列化程序错误或其他异常):
{
"error": {
"name": ["this field is required"]
}
}
我的代码:
renderer_classes = [CustomJSONRenderer] # adds 'data' key
def get_exception_handler(self)
return custom_exception # adds 'error' key to output for errors
我的输出:
成功:(好)
{
"data": {
"id": 123,
"name": "Django"
}
}
错误:(错误)
{
"data": { # Remove this key
"error": { # this should be first key for output
"name": ["This field required"]
}
}
}