使用rest控制台djang无法从post请求中获取正确的json

2024-04-26 10:58:24 发布

您现在位置:Python中文网/ 问答频道 /正文

当我要从googlechrome的高级rest控制台POST请求中获取json时,我将整个数据作为一个键,空字符串作为一个值

我的json是:

{
    "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"
}

为了获取这个json,我使用了视图.py文件:

def create(self, request):

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

但是通过这个我得到了多值dictkeyerror:

我使用的是django rest框架,python。你知道吗


Tags: 数据namerestidjsonnumberdatarequest