Handling Ajax Json Object In Django - 'querydict' Object Has No Attribute 'read' Error
I am trying to parse json object in my Django view which has been passed through from client by ajax via post method. JS: $.post ('/update_vendor_merchandise_types/', JSON.stringif
Solution 1:
request.POST
is for form-encoded content. For JSON, you should access the plain body directly:
json_object = json.loads(request.body)
Solution 2:
Why do you convert json_obj into string when sending it to server? I think you should do it in this way:
json_obj = {"key1": "value1", "key2": "value2"}
$.post('/update_vendor_merchandise_types/', json_obj)
In this case on the server side you can access sent data in this way:
v1 = request.POST["key1"]
Post a Comment for "Handling Ajax Json Object In Django - 'querydict' Object Has No Attribute 'read' Error"