当我,我将从谷歌浏览器的高级休息控制台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"
}
使用我的views.py文件中的代码获取此json:
def create(self, request):
data=request.POST
print data
print "school_id",data.get('school_id')
但是我得到了MultiValueDictKeyError错误:
我正在使用django restframework,python。
答案 0 :(得分:0)
import json
和data=json.loads(request.body)
代替data=request.POST
您的数据将显示在request.body
中。我假设这不是表单提交Ajax调用。