Home > Mobile >  List from key in Django QueryDict return one element instead of the whole list
List from key in Django QueryDict return one element instead of the whole list

Time:09-28

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

  • Related