I am using Django and I am accessing request.POST
from my view. The code is as follows:
data = request.POST
print(data)
Which returns:
<QueryDict: {'name': ['Sam'], 'phone': [' 10795524594'], 'message': ['Es-sénia'], 'Coupon': [''], 'csrfmiddlewaretoken': ['xcGnoJOtnAmXcUBXe01t7ItuMC8BAFHE
6H9Egqd8BuooxLbp3ZrqvwzTZAxukMJW', 'xcGnoJOtnAmXcUBXe01t7ItuMC8BAFHE6H9Egqd8BuooxLbp3Zrq``vwzTZAxukMJW'], 'Size': ['S', 'M']}>
But, whether using .dict()
method or using data.get("Size")
, I only get one element; not the whole list. How can I fix this?
CodePudding user response:
Use data.getlist(key)
. It is a bit weird, see the docs: https://docs.djangoproject.com/en/3.2/ref/request-response/#django.http.QueryDict.getlist