0

when i,m going to fetch the json from google chrome's advanced rest console POST request i'm getting my whole data as a key and empty string as a value

my json is :

{
    "school_id" : "1",
    "registration_no" : "",
    "first_name" : "Anmol",
    "middle_name" : "987686853",
    "last_name" : "",
    "student_category_id" : "null",
    "date_of_birth" : "1991-01-01",
    "gender" : "MALE",
    "street_address" : "",
    "student_city" : "",
    "student_state" : "",
    "student_country" : "",
    "pin_code" : "",
    "religion" : "",
    "nationality" : "",
    "phone_number" : "",
    "mobile_number" : "987686853",
    "email" : "ab@cd.ef",
    "previous_institution_name" : "BFCET",
    "board" : "g",
    "latest_course" : "grapes",
    "passing_year" : "675",
    "percentage_marks" : "56",
    "course" : "1",
    "batch" : "2",
    "image" : "null",
    "is_active" :" true"
}

to fetch this json i'm using the code in my views.py file:

def create(self, request):

        data=request.POST
        print data
        print "school_id",data.get('school_id')

but by this i'm getting MultiValueDictKeyError error:

i'm using django restframework ,python.

1 Answers1

0

import json and data=json.loads(request.body) instead of data=request.POST

Your data will be there in request.body. I am assuming this is not a form submit Ajax call.

Barun Sharma
  • 1,452
  • 2
  • 15
  • 20