Reputation: 23
I am posting values from the frontend using jQuery to django on the backend.
I use
list = request.POST
print list
which returns:
<QueryDict: {u'country': [u'test'], u'town_select[]': [u'town3', u'town4', u'town5']}>
I want to retrieve the town_select[]
list but when I do
town = list.get('town_select[]')
and print it I only get the last town in the list town5
. I want to get all three towns.
If anyone knows what I've done wrong it would be greatly appreciated.
Thanks
Upvotes: 2
Views: 169
Reputation: 13058
You need to use the getlist
method on request.POST
.
request.POST.getlist('town_select[]')
Upvotes: 1
Reputation: 11429
You should use
town = request.POST.getlist('town_select')
or maybe
town = request.POST.getlist('town_select[]')
as this answer suggests.
Upvotes: 1