我有一個例外,這使我的錯誤,從形式像::Python的驗證錯誤的對象不是JSON序列化
except ValidationError as e:
return JsonResponse(e, safe=False)
據giveing我的錯誤 ValidationError({'age': [u'This field is required.'], 'name': [u'This field is required.']}) is not JSON serializable
爲什麼我得到這個錯誤,我怎麼能使它工作..任何想法?
?請嘗試顯示[mcve] – Sayse
@Sayse我張貼從窗體ajax,所以我想發送錯誤作爲迴應.. – gamer
不知道你爲什麼 - - 我。但Sayse的觀點仍然有效。表單將驗證錯誤收集到一個錯誤列表中,這就是你應該序列化。在任何情況下,都不要從表單方法中返回響應。 –