webpy, how to extra add data to a form?

懵懂的女人 提交于 2019-12-08 01:20:20

问题


i need a form with "records" generated from the db.

For each DB record, in addition to form fields, it need to contain also images & record description, e.g.

<tr> <td> rec 15, <img src=fnamex.jpg>, <input name=inp15> <checkbox name=chk15> </td> </tr>

so i'm confused about the how, when & where to create the form:

  1. should the form generation method occur in my "model.py" ? in the template ?
  2. how do I keep all the element of a "record" together for later iteration in the template ?
  3. where should i add the "extra" data (e.g. image source & title) ? to the form object? in a paralel object list?

回答1:


To add elements to a Web.py form function, you can do this:

    args = ()
    for a in range(0,2):
        args = args + (web.form.Textbox(a), ) # Forces tuple type
    tmp = web.form.Form(*args)


来源:https://stackoverflow.com/questions/11483154/webpy-how-to-extra-add-data-to-a-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!