Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding Django's QueryDict List limitations

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
like image 210
vii Avatar asked Dec 28 '22 14:12

vii


1 Answers

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)

like image 56
akonsu Avatar answered Jan 06 '23 20:01

akonsu