new to app engine - how to handle control arrays

1 view
Skip to first unread message

mikemoum

unread,
Jul 25, 2010, 7:17:36 PM7/25/10
to Google App Engine
Hi,

I'm just getting started with app engine, and am porting a php site I
developed as a learning tool. The input form on my page allows one to
enter a number of participants in a small school program. As such,
some fields are common to many people, such as last name. In my input
form, therefore, there are a column of textboxes, with name=lname[].
When the form is posted when the submit button is clicked, the global
php variable, $_POST, contains the field lname[], which is an array of
entries.

It's not clear to me how to handle such an array when it is posted in
app engine and parsed with python. How does one do this?

Thanks for your replies,
Mike

Alon Carmel

unread,
Jul 26, 2010, 5:16:33 AM7/26/10
to google-a...@googlegroups.com
first, it depends on how your working with python on app engine.

django :
self.request.GET/POST['VARNAME'] or django request.GET/POST['VARNAME']

The .POST or .GET are dictionaries of all the passed data. you can also access them via .REQUEST.

For example:

myarray = request.POST['myarray']

for item in myarray:
   //do something

you can also print those arrays to see the structure... dir or print.


-
Cheers,

def AlonCarmel(request)
     import simplejson as json
     contact = {}
     contant['email'] = 'a...@aloncarmel.me'
     contact['twitter'] = '@aloncarmel'
     contact['web'] = 'http://aloncarmel.me
     contact['phone'] = '+972-54-4860380'
     return HttpResponse(json.dumps(contact))

* If you received an unsolicited email from by mistake that wasn't of your matter please delete immediately. All E-mail sent from Alon Carmel is copyrighted to Alon Carmel 2008. Any details revealed in e-mails sent by Alon Carmel are owned by the Author only. Any attempt to duplicate or imitate any of the Content is prohibited under copyright law 2008.




--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.


Mike Moum

unread,
Jul 26, 2010, 4:26:15 PM7/26/10
to google-a...@googlegroups.com
Here's what I'm trying to do:

class Process(webapp.RequestHandler):
def post(self):
self.response.out.write('hello<br />')
data = self.request.get('test[]')
for d in data:
self.response.out.write(d)

class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('<html><body>')
self.response.out.write("""
<form action="/process" method="post">
<input type="text" name="test[]" />
<br />
<input type="text" name="test[]" />
<br />
<input type="text" name="test[]" />
<br />
<input type="text" name="test[]" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>""")
self.response.out.write('</body></html>')

The MainPage generates a form with four textboxes, each with name =
"test[]".
Submit sends the output to Process. With php, _POST[test[]] is an array
with four values, the values being the text entered into each of the
test boxes.
In app engine, self.request.get('test[]') apparently only gets the value
of the first text box.
So my question is whether there is a way to have an array of text boxes,
and to retrieve the value of each of them in a list or other data structure.
I know that I can generate the text boxes so that they are names test1,
test2, test3, and test4, and then write code to loop through and build
the text box names, and issue a get for each name, but that seems really
clunky and error prone.

Thanks for any help,
Mike

On 07/26/2010 04:16 AM, Alon Carmel wrote:
> first, it depends on how your working with python on app engine.
>
> django :
> self.request.GET/POST['VARNAME'] or django request.GET/POST['VARNAME']
>
> The .POST or .GET are dictionaries of all the passed data. you can
> also access them via .REQUEST.
>
> For example:
>
> myarray = request.POST['myarray']
>
> for item in myarray:
> //do something
>
> you can also print those arrays to see the structure... dir or print.
>
>
> -
> Cheers,
>
> def AlonCarmel(request)
> import simplejson as json
> contact = {}

> contant['email'] = 'a...@aloncarmel.me <mailto:a...@aloncarmel.me>'

> <mailto:google-a...@googlegroups.com>.


> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com

> <mailto:google-appengine%2Bunsu...@googlegroups.com>.

Mike Moum

unread,
Jul 26, 2010, 5:50:23 PM7/26/10
to google-a...@googlegroups.com
Got it. Need to use request.get_all()

On 07/26/2010 04:16 AM, Alon Carmel wrote:

> first, it depends on how your working with python on app engine.
>
> django :
> self.request.GET/POST['VARNAME'] or django request.GET/POST['VARNAME']
>
> The .POST or .GET are dictionaries of all the passed data. you can
> also access them via .REQUEST.
>
> For example:
>
> myarray = request.POST['myarray']
>
> for item in myarray:
> //do something
>
> you can also print those arrays to see the structure... dir or print.
>
>
> -
> Cheers,
>
> def AlonCarmel(request)
> import simplejson as json
> contact = {}

> contant['email'] = 'a...@aloncarmel.me <mailto:a...@aloncarmel.me>'

> <mailto:google-a...@googlegroups.com>.


> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com

> <mailto:google-appengine%2Bunsu...@googlegroups.com>.

Reply all
Reply to author
Forward
0 new messages