当我要从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。你知道吗
import json
和data=json.loads(request.body)
而不是data=request.POST
您的数据将出现在
request.body
。我假设这不是表单提交Ajax调用。你知道吗相关问题 更多 >
编程相关推荐