webpy, how to extra add data to a form?

2019-05-26 18:12发布

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条回答
女痞
2楼-- · 2019-05-26 18:27

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)
查看更多
登录 后发表回答