【发布时间】:2017-01-04 18:00:44
【问题描述】:
我将 Django rest-auth 包与 Django allauth 一起使用,以允许用户使用 /res-auth/registration api 调用进行注册。
如果注册失败,我会收到一些 JSON 返回到我的 Javascript Web 应用程序,其中包含失败的原因。我很难弄清楚如何为所有情况提取错误原因。以下是用户名过短时返回的 JSON 示例:
{
"_body":"{\"password1\":[\"This password is too short. It must contain at least 8 characters.\"]}",
"status":400,
"ok":false,
"statusText":"Bad Request",
"headers":{
"Date":[
"Sun",
" 28 Aug 2016 16:56:40 GMT"
],
"Content-Type":[
"application/json"
],
"Server":[
"WSGIServer/0.2 CPython/3.4.3"
],
"X-Frame-Options":[
"SAMEORIGIN"
],
"Access-Control-Allow-Origin":[
"*"
],
"Allow":[
"POST",
" OPTIONS"
]
},
"type":2,
"url":"http://al8f24a9.ngrok.io/rest-auth/registration/"
}
如果是密码或用户名,我将如何提取失败原因?
【问题讨论】:
标签: javascript json django rest