request.args

115 views
Skip to first unread message

goome

unread,
Jan 17, 2016, 5:12:16 AM1/17/16
to web2py-users
i have this url : http://127.0.0.1:8000/PROVE/dettaglio_aggiornamenti/SPE/SPE_2016011518051300.csv generated by:
href="{{=URL(r=request,f='dettaglio_aggiornamenti',args=['SPE',ultimoFileSpe])}}
i believed that
request.args[0] == 'SPE'
and
request.args[1]== 'SPE_2016011518051300.csv'

but i got :
"""

<type 'exceptions.IndexError'> list index out of range


Function argument list

()

Code listing
1520.
1521.
1522.
1523.
1524.
1525.

1526.
1527.
1528.
1529.
    records=legacy_db(legacy_db.SFIMDB.filename==ufile).select()
return dict(records=records)


def dettaglio_aggiornamenti():
tab = request.args[0]

b=request.args[1]



Variables
global request <Storage {'_vars': None, 'function': 'dettaglio_...marcello/CODE/MIEI/WEB2.10/applications/PROVE/'}>
request.args []
tab undefined

"""

Why request.args turns to be undefined

Niphlod

unread,
Jan 17, 2016, 8:06:51 AM1/17/16
to web2py-users
are you using routes.py ?

goome

unread,
Jan 17, 2016, 11:24:04 AM1/17/16
to web2py-users
i have route_in that about this app has :
('/PROVE','/PROVE/default/index')

Anthony

unread,
Jan 17, 2016, 1:49:37 PM1/17/16
to web2py-users
Is that all you have in routes, because your URL excludes the controller, which would also be implemented via the routes?

Also, when you get that error, is the exact URL in the address bar of the browser http://127.0.0.1:8000/PROVE/dettaglio_aggiornamenti/SPE/SPE_2016011518051300.csv?

goome

unread,
Jan 17, 2016, 3:25:49 PM1/17/16
to web2py-users
this is making me mad(i think i am missing somethng obvious, bt i don't know what):
This work:
def vistaSIMFDB():
  ufile=request.args[0]
  #ufile='SIMFDB_2016011509341800.csv'
  form=legacy_db(legacy_db.SIMFDB.filename==ufile).select()
  #form = SQLFORM.grid(legacy_db.SIMFDB.filename==ufile,  csv=True )
  return dict(form=form)


This , which use SQLFORM.grid, but no request.args, also work:
def vistaSIMFDB():
  #ufile=request.args[0]
  ufile='SIMFDB_2016011509341800.csv'
  #form=legacy_db(legacy_db.SIMFDB.filename==ufile).select()
  form = SQLFORM.grid(legacy_db.SIMFDB.filename==ufile,  csv=True )
  return dict(form=form)


This (sqlform.grid with a parameter got from request.args) not:
i am redirect to http://127.0.0.1:8000/PROVE/vistaSIMFDB?_signature=c3d5a81a14fa239430285e2444c0f0fb568aba2d
:

Ticket ID

127.0.0.1.2016-01-17.21-21-32.80e5e27e-d857-4431-9876-a44d3c169182

<type 'exceptions.IndexError'> list index out of range

Version

web2py™ Version 2.10.4-stable+timestamp.2015.04.26.15.11.54
Python Python 2.7.6: /usr/bin/python (prefix: /usr)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Traceback (most recent call last):
File "/home/marcello/CODE/MIEI/WEB2.10/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/home/marcello/CODE/MIEI/WEB2.10/applications/PROVE/controllers/default.py", line 1559, in <module>
File "/home/marcello/CODE/MIEI/WEB2.10/gluon/globals.py", line 393, in <lambda>
self._caller = lambda f: f()
File "/home/marcello/CODE/MIEI/WEB2.10/applications/PROVE/controllers/default.py", line 1522, in vistaSIMFDB
ufile=request.args[0]
IndexError: list index out of range

Error snapshot help

<type 'exceptions.IndexError'>(list index out of range)

inspect attributes

Frames

  • File /home/marcello/CODE/MIEI/WEB2.10/gluon/restricted.py in restricted at line 227 code arguments variables

  • File /home/marcello/CODE/MIEI/WEB2.10/applications/PROVE/controllers/default.py in <module> at line 1559 code arguments variables

  • File /home/marcello/CODE/MIEI/WEB2.10/gluon/globals.py in <lambda> at line 393 code arguments variables

  • File /home/marcello/CODE/MIEI/WEB2.10/applications/PROVE/controllers/default.py in vistaSIMFDB at line 1522 code arguments variables

    Function argument list

    ()

    Code listing
    1517.
    1518.
    1519.

  • 1520.
    1521.
    1522.

    1523.
    1524.
    1525.
    1526.
  •     form=legacy_db(legacy_db.STK.filename==ufile).select()
    return dict(form=form)


    def vistaSIMFDB():
    ufile=request.args[0]

    #ufile='SIMFDB_2016011509341800.csv'
    #form=legacy_db(legacy_db.SIMFDB.filename==ufile).select()
    form = SQLFORM.grid(legacy_db.SIMFDB.filename==ufile, csv=True )
    return dict(form=form)
    Variables
    global request <Storage {'_vars': None, 'function': 'vistaSIMFD...marcello/CODE/MIEI/WEB2.10/applications/PROVE/'}>
    request.args []
    ufile undefined

so that the problem seems to be with grid and request.args togheter, which seems quite bizarre, also becouse the ticket point to fails in request.args, while grid is called after

Massimo Di Pierro

unread,
Jan 17, 2016, 8:10:32 PM1/17/16
to web2py-users
should eb

def vistaSIMFDB():
ufile=request.args(0)

#ufile='SIMFDB_2016011509341800.csv'
#form=legacy_db(legacy_db.SIMFDB.filename==ufile).select()
form = SQLFORM.grid(legacy_db.SIMFDB.filename==ufile, csv=True, args=request.args[:1] )
return dict(form=form)

you have to tell the grid which args to exclude.

goome

unread,
Jan 18, 2016, 4:29:56 AM1/18/16
to web2py-users
Thank you!
It works, but i cannot understnd how and why.
Could you explain?
How is grid interested in request.args(if i don't use it as such, but copy args[0] in ufie and pass that to grid)?

Anthony

unread,
Jan 18, 2016, 8:18:49 AM1/18/16
to web2py-users
On Monday, January 18, 2016 at 4:29:56 AM UTC-5, goome wrote:
Thank you!
It works, but i cannot understnd how and why.
Could you explain?
How is grid interested in request.args(if i don't use it as such, but copy args[0] in ufie and pass that to grid)?

The grid creates a number of links, such as those for creating, viewing, and editing records -- each of those links must point back to the action that created the grid, so the grid adds URL args to further specify the particular function requested. If the base URL already includes some additional URL args used for other purposes, you must tell the grid so it will ignore those args and append its own args to those in the base URL.

Anthony

goome

unread,
Jan 18, 2016, 12:04:47 PM1/18/16
to web2py-users
ah ok, tanks a lot
Reply all
Reply to author
Forward
0 new messages