I'm trying to send data from a webpage to a django view to be saved as serialized json to a database. If possible, I would like to avoid django's QueryDict object and just read the request with simplejson, flatten, and save to the database. What is the best way to send the data so simplejson can flatten it?
var languages = {};
languages['english'] = ['mark', 'james'];
languages['spanish'] = ['amy', 'john'];
$.ajax({
type: 'POST',
url: '/save/',
data: languages,
dataType: 'json'
});
.
if request.is_ajax() and request.method == 'POST':
for key in request.POST:
print key
valuelist = request.POST.getlist(key)
print valuelist
I doubt that it is possible to make django avoid creating QueryDict, but you can ignore it (from iphone Json POST request to Django server creates QueryDict within QueryDict):
def view_example(request):
data=simplejson.loads(request.raw_post_data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With