3

Using python and wsgiref.handlers, I can get a single variable from a form with self.handler.request.get(var_name), but how do I iterate through all form variables, be they from GET and POST? Is it something like this?

for field in self.handler.request.fields:
value = self.handler.request.get(field)

Again, it should include both fields included in the POST and fields from the query string, as in a GET request.

Thanks in advance folks...

MarcoB
  • 301
  • 1
  • 2
  • 11

2 Answers2

5

http://code.google.com/appengine/docs/python/tools/webapp/requestclass.html#Request_arguments

for field in self.request.arguments():
  value = self.request.get(field)
Drew Sears
  • 12,812
  • 1
  • 32
  • 41
0

A modification of Drew's answer worked great for me:

params = {}
for field in self.request.arguments():
  params[field] = self.request.get(field)
DanDan
  • 101
  • 1
  • 4
  • 1
    If you're just constructing a dict out of them, you could just refer to `self.request.arguments` directly, which is already a dict. – Nick Johnson Nov 02 '11 at 01:34
  • Good to know, @Nick Johnson. I think I went down this path because the docs say: Returns a `list` of the names of query (URL) or POST data arguments. – DanDan Nov 17 '11 at 15:13