小编Arp*_*thi的帖子

使用 Django Rest Framework 的自定义验证错误消息

DRF 给出的默认验证错误消息是密钥和消息列表。将此格式自定义为文本格式的最佳方法是什么。例如。

这是默认格式。

{
"message": {
    "phone": [
        "customer with this phone already exists."
    ],
    "email": [
        "customer with this email already exists."
    ],
    "tenant_id": [
        "customer with this tenant id already exists."
    ]
},
"success": false,
"error": 1
}
Run Code Online (Sandbox Code Playgroud)

这是我想要的东西。

{
"message": "customer with this phone already exists, customer with this 
email already exists, customer with this tenant id already exists"
"success": false,
"error": 1
}
Run Code Online (Sandbox Code Playgroud)

django django-rest-framework

5
推荐指数
1
解决办法
6188
查看次数

标签 统计

django ×1

django-rest-framework ×1