Reputation: 6849
I use the ajax pass the data to views.py:
var params = {'nood_id':'f55dbe56-7fa8-4d13-8e1e-2dc67499b6ac'}
$.ajax({
type:'post',
url:'/api/nood_detail/',
data:{'params':params},
dataType:'json',
success:success_func,
})
In the views.py, the request.POST
is bellow:
<QueryDict: {u'params[nood_id]': [u'f55dbe56-7fa8-4d13-8e1e-2dc67499b6ac']}>
I can not use the request.POST.get("params") to get the param, nor can I get the nood_id
.
How can I get my params in QueryDict?
Upvotes: 2
Views: 622
Reputation: 16661
This looks not like intended:
<QueryDict: {u'params[nood_id]': [u'f55dbe56-7fa8-4d13-8e1e-2dc67499b6ac']}>
especially not this part: u'params[nood_id]'
. This means your error already happens on the javascript side => somehow your params object was stringified partially? I'm not sure what happenend, it looks fishy to me.
In your Django view, you should be able to use request.POST.get('nood_id')
or however you want the structure - but your JS has to send it correctly.
Try to change the JS to:
var params = {'nood_id':'f55dbe56-7fa8-4d13-8e1e-2dc67499b6ac'}
$.ajax({
type: 'post',
url: '/api/nood_detail/',
data: params,
dataType: 'json',
success: success_func,
})
Upvotes: 1