How to change validation error responses in DRF?

后端 未结 3 969
执笔经年
执笔经年 2021-02-19 00:03

I want to change the JSON, which rest_framework or django returns when a validation error occures.

I will use one of my views as example, but I want to change error mess

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 00:48

    if not serializer.is_valid(raise_exception=False)
        return Response(serializer.errors.values(), status=status.HTTP_400_BAD_REQUEST)
    

提交回复
热议问题