金字塔中的HTML表单名称数组解析(Python)(HTML form name array parsing in Pyramid (Python))

其他开发 IT屋
百度翻译此文   有道翻译此文
问 题

Is there any way for Pyramid to process HTML form input which looks like this:

<input type="text" name="someinput[]" value="" />

or even more usefully:

<input type="text" name="someinput[0][subelement1]" value="" />
<input type="text" name="someinput[0][subelement2]" value="" />
<input type="text" name="someinput[1][subelement1]" value="" />
<input type="text" name="someinput[1][subelement2]" value="" />

...and access that data easily (e.g. via a dict)?

Any help would be much appreciated!

EDIT: to make it clearer, what I need is the ability to have a form where a user can add as many 'instances' of a group of input elements, e.g. adding between 1 and n users, each containing a firstname, lastname, username (or something like that).

解决方案

One solution would be to use peppercorn. Although it does not support the syntax you're looking for, it will let you send structured data to your Pyramid application through the use of forms. A more casual description exists too.

本文地址:IT屋 » HTML form name array parsing in Pyramid (Python)

问 题

Pyramid 有什么方法来处理HTML表单输入,看起来像这样:



 < input type =“text”name =“someinput []”value =“”/> 


甚至更有用:

 < input type =“text”name =“someinput [0] [subelement1]”value =“”/> 
< input type =“text”name =“someinput [0] [subelement2]”value =“”/>
< input type =“text”name =“someinput [1] [subelement1]”value =“”/>
< input type =“text”name =“someinput [1] [subelement2]”value =“”/>


...并轻松访问数据(例如通过字典)?



任何帮助都将非常感谢!



编辑:使其更清晰,我需要的是能够具有用户可以添加一组输入元素的多个“实例”的形式,例如,添加1到 n 个用户,每个用户包含 firstname , lastname ,用户名(或类似的东西)。

解决方案

a href =“http://docs.pylonsproject.org/projects/peppercorn/dev/”rel =“nofollow”> peppercorn 。虽然它不支持您要查找的语法,但它可以让您通过使用表单将结构化数据发送到Pyramid应用程序。 还有一个更随便的描述


本文地址:IT屋 » 金字塔中的HTML表单名称数组解析(Python)

官方微信
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起