我想将电子应用程序的请求发布到Django应用程序。发布后,我可以获得email
的数据,但无法获得answer
。即使我随同发布数据,它也是空的。 answer
是对象数组。
电子(.js)文件
$(".submit-btn").click(() => {
var submit_answer = []
var lock = false
if(lock == false){
for(var i = 0; i < questions.length; i++){
localforage.getItem(Q[i], (err,value) => {
submit_answer.push(value)
})
}
lock=true
}
if(lock == true){
console.log(submit_answer)
// output array of objects
request({
method: 'POST',
url: "http://127.0.0.1:8000/get_question_lists/",
json: true,
body: {
email: email,
answer: submit_answer,
},
}).on('data', function(data) {
// ipcRenderer.send("submit-test", email)
});
}
})
django(views.py)文件
@csrf_exempt
def get_question_lists(request):
"""
API to get a list of questions
"""
if request.method == 'GET':
...
elif request.method == 'POST':
data = JSONParser().parse(request)
print data
print data['email']
print data['answer']
# print empty array
return None