4π
β
The problem is that you are You are converting to JSON twice β once when you call as_json
, then again when you use JsonResponse
.
You could use HttpResponse
with form.errors.as_json()
:
return HttpResponse(user_form.errors.as_json(), status = 400, content_type='application/json')
Note the warnings in the as_json
docs about escaping results to avoid a cross site scripting attack. You should ensure the results are escaped if you use JsonResponse
as well.
π€Alasdair
Source:stackexchange.com