Jquery to Python / Django Query Dict -
i'm post
ing array using jquery such:
var fees = []; fees.push({ "fee":somefee0, "deadline": somedeadline0, "category": somecategory0}) }); fees.push({ "fee":somefee1, "deadline": somedeadline1, "category": somecategory1}) }); jquery.ajax({ type: 'post', url: /save/, data: {fees:fees}, success: ...
when post
data django app, shows such:
<querydict: {u'fees[1][deadline]': [u'31'], u'fees[0][category]': [u'43'], u'fees[1][fee]': [u'fdsa'], u'fees[1][category]': [u'44'], u'fees[0][fee]': [u'fdas'], u'fees[0][deadline]': [u'31']}>
how can access such use data meaningful objects.
# fees[0], fees[1] turned int dicts of format {"category": 43, "fee": "fdas", "deadline": 31}
alternatively, if use json.stringify(fees)
in jquery, post
data turns strange:
<querydict: {u'[{"fee":"fdsa","deadline":"31","category":"43"},{"fee":"fdsa","deadline":"31","category":"44"}]': [u'']}>
however can access relevant data desire using:
x = request.post values in x.lists(): data = json.loads(values[0]) print data[0]['fee'], data[1]['deadline']
i feel duct tape , band-aids though. doing wrong / happening here?
use json.stringify
version data in python via json.loads(request.body)
.
Comments
Post a Comment