1
I donβt think this happens when my frontend posts data.
The same key can be associated multiple times to a value, for example when you use a checkbox with:
<input type="checkbox" name="foo" value="bar">
<input type="checkbox" name="foo" value="qux">
If you check both checkboxes, it will add foo=bar&foo=qux
to the request body, so the same key (foo
) is associated to both bar
and qux
.
If you use request.POST['foo']
it will return the value of the last record, so 'qux'
. You can also use request.POST.getlist('foo')
it will return all values for that key in a list, so ['bar', 'qux']
.
Source:stackexchange.com