我试图弄清楚如何使用 django 将 postman 中的原始 JSON 数据推送到我的 rest api 并使用该数据进行一些计算。
我已经尝试了几个代码片段,但我无法弄清楚
这是我的 JSON:
{
"Dependents": 1,
"ApplicantIncome": 4583,
"CoapplicantIncome": 1508,
"LoanAmount": 128000,
"Loan_Amount_Term": 360,
"Credit_History": 1,
"Gender_Female": 0,
"Gender_Male": 1,
"Married_No": 0,
"Married_Yes": 1,
"Education_Graduate": 1,
"Education_Not Graduate": 0,
"Self_Employed_No": 1,
"Self_Employed_Yes": 0,
"Property_Area_Rural": 1,
"Property_Area_Semiurban": 0,
"Property_Area_Urban": 0
}
这是python代码:
@api_view(["POST"])
def ClientData(request):
return Response(request.data)
上述代码显示邮递员响应中的 JSON 文件
现在我想在另一个函数中使用上面的响应来做一些计算
def NewData(request):
data = ClientData(request)
newsum=data['LoanAmount']*4
print(newsum)