How to change validation error responses in DRF?

后端 未结 3 995
执笔经年
执笔经年 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条回答
  •  旧时难觅i
    2021-02-19 00:56

    The easiest way to change the error style through all the view in your application is to always use serializer.is_valid(raise_exception=True), and then implement a custom exception handler that defines how the error response is created.

提交回复
热议问题