Reputation: 26728
I am trying to access the post data from the form , below is my view
def retrieve_emails(request):
if request.method == 'POST':
print request.POST, ">>>>>>>>>>>>>>>>POST"
if request.POST.has_key('invite'):
print request.POST['invite'],"------------------> all values"
return render_to_response('response.html', context_instance=RequestContext(request))
result
<QueryDict: {u'csrfmiddlewaretoken': [u'GoxxxxxxxxDxxxxxxopg'], u'invite': [u'<[email protected]>', u'<[email protected]>']}> >>>>>>>>>>>>>>>>POST
<[email protected]> ------------------>all values
As you can observe from the above result, i can able to get a list of emails
for the key invite
when we print the request.POST
, but when we try to access/print the key invite
as in the above code, its printing only one email
from the list
Can anyone please let me know,why is it happening, and why it is returning only one email instead of list of emails ?
Upvotes: 1
Views: 1416
Reputation: 8623
You have to use getlist() to get all values, otherwise you can only get the last value. So you need:
request.POST.getlist('invite')
Hope it helps.
Upvotes: 4