why request.vars are added an additional key “records” with null value when I used the sqlform.grid?

15 views
Skip to first unread message

Yibing Liu

unread,
Sep 12, 2016, 2:37:13 AM9/12/16
to web2py-users

    My web2py version is 2.14.6.

    I define a form in myview.html

   `<form action="{{=URL('default','sj_xxxx')}}" method='get'>
    <input id='shizhou' name='shizhou'>
    <input id='xianqu' name='xianqu'>
    <input id='xiangzhen' name='xiangzhen'>
    <input type="submit" value="query">
    </form>` 

     In my default controler function 'index' I want to deal with the request.vars passed from html.It works fine. Then I add a form=SQLFORM.grid(query) to my function, I find that the request.vars are added an additional key "records" with null value when the sqlform.grid() line is executed. So I debug into the source code, I find the line 2479 in sqlhtml.py is

elif not request.vars.records: request.vars.records = []

    After the above line excuted my request.vars was added an additional key "records" with null value. My questions are,

    1.How can I prevent adding the "record" key to my request.vars?

    2.What's the purpose of the code

elif not request.vars.records: request.vars.records = []

Niphlod

unread,
Sep 12, 2016, 5:31:55 AM9/12/16
to web2py-users
it's to hold selected lines, I think. Anyway, you should use request.get_vars to get your data (since your method is "get"). Also, please note that the grid is coded in such a way that the grid is the sole "manager" of the request/response cycle, so fiddling in the same page with your own pieces of code may result in issues.

Yibing Liu

unread,
Sep 12, 2016, 6:29:06 AM9/12/16
to web2py-users
Thank you very much. Your answer is very clear.

在 2016年9月12日星期一 UTC+8下午5:31:55,Niphlod写道:

Anthony

unread,
Sep 12, 2016, 8:19:28 AM9/12/16
to web2py-users
Reply all
Reply to author
Forward
0 new messages