HTML form passing values to web2py

时光总嘲笑我的痴心妄想 提交于 2019-12-06 07:40:55

When you submit a form to web2py (via GET or POST), all the form variables will be available in request.vars (for more on this, see the book sections on Dispatching and the request object as well as the chapter on forms).

So, you could do something like:

def search():
    rows = None
    if request.vars:
        query = reduce(lambda a, b: (a & b),
            (db.mytable[var] == request.vars[var] for var in request.vars))
        rows = db(query).select()
    return dict(rows=rows)

Note, the reduce() with the generator expression is equivalent to writing a query like this:

(db.mytable.field1 == request.vars.field1) & \
(db.mytable.field2 == request.vars.field2) & \
...
(db.mytable.fieldN == request.vars.fieldN)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!