Opened 11 years ago

Closed 11 years ago

#20379 closed Uncategorized (invalid)

request.POST.getlist fails when submitting a JS array of JS objects

Reported by: Alex Krupp <alex.krupp@…> Owned by: nobody
Component: Uncategorized Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As described in the summary, request.POST.getlist fails when applied to an array of objects instead of an array of strings:

This works:

Frontend:
var test = ['a', 'b', 'c']
$.post("/upload", {"test": test}, function(response) {alert(response);});

Backend:
print request.POST.getlist('test[]')

[u'a', u'b', u'c'] #Success

This fails:

Frontend:
var foo = {}
foo.bar = "asdf"
test = [foo, foo, foo]
$.post("/upload", {"test": test}, function(response) {alert(response);});

Backend:

print request.POST.getlist('test[]')

[] #Fail

Change History (1)

comment:1 by Claude Paroz, 11 years ago

Resolution: invalid
Status: newclosed

I don't think your frontend code is valid. You should either properly serialize your objects client-side, or use a JSON structure, depending on the complexity of your objects.

If you still think that Django is at fault, please provide the detailed POST structure of the HTTP request.

Note: See TracTickets for help on using tickets.
Back to Top