Python中的HTML输入数组解析(GAE) [英] HTML input array parsing in Python (GAE)
问题描述
我在HTML中有一个输入数组,如下所示:
< input type =textname =p_item []>
< input type =textname =p_item []>
< input type =textname =p_item []>
我想在Python中解析输入,我试着这样做, :
items = self.request.get('p_item')
for n in range(1,len(项目)):
self.response.out.write('Item'+ n +':'+ items [n])
这样做的正确方法是什么?
p>
< input type =textname =p_item>
< input type =textname =p_item>
< input type =textname =p_item>
并使用self.request.get_all()方法 http://code.google.com/appengine/docs/python/tools/webapp/requestclass.html #Request_get_all
ps作为参考,没有关于GET / POST数据的数组概念,您的表单被转换为由'&'分隔的key = value字符串,例如
p_item = 1& p_item = 3& p_item = 15
等等,这取决于Web框架来解释一个参数是否是一个数组。
编辑:哎呀,只要阅读你已经知道的评论,哦:P
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
<input type="text" name="p_item">
<input type="text" name="p_item">
<input type="text" name="p_item">
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.
p_item=1&p_item=3&p_item=15
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
这篇关于Python中的HTML输入数组解析(GAE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!