python可以处理html表单中的复杂字段名吗?
在 php 中,我们可以像这样调用表单字段
<input type="text" name="obj[obj_id][name]" value="val1" />
,因此在请求中我们有多维数组。
array('obj_id'=> array('name'=> 'val1'))
Python(或者它取决于框架?)不理解这些字段,并且根据请求我们
'obj[obj_id][name]' = [val1, val2]
之前使用过
<input type="checkbox" name="obj" value="${json.dumps([name, val1])}" />
并将字段内容作为Python列表获取,
obj = json.loads(obj)
这样
name, val1 = obj
就可以了。
但它仅对复选框方便,对输入文本字段不方便。 有什么解决办法吗?
我正在将cherrypy 3与genshi一起使用(+ python 3,如果这很重要)
UPD
最近注意到,设置表单 enctype="multipart/form-data" 会使同名的复选框也不起作用,因此第三个代码示例
'obj[obj_id][name]' = [val1, val2]
不起作用。
In php we can call form fields like
<input type="text" name="obj[obj_id][name]" value="val1" />
So in request we have multidimensional array.
array('obj_id'=> array('name'=> 'val1'))
Python(or it depends on framework?) don't understand such fields and in request we have
'obj[obj_id][name]' = [val1, val2]
I have used before
<input type="checkbox" name="obj" value="${json.dumps([name, val1])}" />
and to get field content as a python list
obj = json.loads(obj)
so
name, val1 = obj
works.
But it is convenient only for checkboxes and not for input text fields.
Is there any solution?
I am using cherrypy 3 with genshi (+ python 3, if that matters)
UPD
Have recently noticed, that setting form enctype="multipart/form-data" makes checkboxes with the same names also non-working, so the third code example
'obj[obj_id][name]' = [val1, val2]
doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论