I'm two days in to Python and GAE, thanks in advance for the help.
I have an input array in HTML like this:
<input type="text" name="p_item[]">
<input type="text" name="p_item[]">
<input type="text" name="p_item[]">
I want to parse the input in Python, and I'm trying this, which isn't working:
items = self.request.get('p_item')
for n in range(1,len(items)):
self.response.out.write('Item '+n+': '+items[n])
What is the correct way to do this?
Change your html to this
and use the self.request.get_all() method http://code.google.com/appengine/docs/python/tools/webapp/requestclass.html#Request_get_all
p.s. For reference, there is no concept of arrays for GET/POST data, your form gets transformed a key=value string separated by '&' e.g.
etc, it's up to the web framework to interpret whether a parameter is an array.
Edit: oops, just read the comments that you figured this out already, oh well :P
I would recommend doing some debugging if this sort of issue comes up. Make things simple and write out your variable values and ensure you get what you expect at each step. Do something like the following:
And see what happens when running the following Python on the backend:
Based on the output you should have a better idea of what to get the desired results or how to add more detail to your question if you still don't understand a certain behavior.