user1597122
user1597122

Reputation: 327

use request.POST without knowing the name and number of inputs

Is there a way that become aware of name and value of inputs in request.POST? I know i can access the value of inputs by knowing name of them like this:

name = request.POST['inputName']

but if i don't know how many inputs and with what names they are, what can i do? is there a way to loop through request.POST? (i create my html with xsl, and because i'm creating html by parsing xml file, the number and nmame of inputs are variable. so i have to use this way) really thanks for your help :)

Upvotes: 4

Views: 1461

Answers (2)

Burhan Khalid
Burhan Khalid

Reputation: 174692

The default iterator of Python dictionaries returns keys - what this means is that when you loop through a dictionary, it will return each key. Since request.POST is a "dict like" object, it works:

for i in request.POST:
   print 'I have been passed the following keys: ',i

You can also do:

print 'The total number of keys in my POST request: ', len(request.POST.keys())

Upvotes: 8

Timofei Mihhailov
Timofei Mihhailov

Reputation: 1

Try to just foreach them. Example:

foreach(request.POST as item){
 print item;
}

Upvotes: -3

Related Questions