Opened 12 years ago
Closed 12 years ago
#20379 closed Uncategorized (invalid)
request.POST.getlist fails when submitting a JS array of JS objects
Reported by: | 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
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.