我正在尝试一个web2py应用here,我收到错误消息。我在StackOverFlow和其他Web资源上尝试了多种解决方案,但无法使其工作。我知道这是列表中的问题,但是指向正确的方向很有帮助。然而,我尝试了几个解决方案,没有为我工作。Web2py错误:<type'exceptions.IndexError'>列表索引超出范围
CODE:
def __edit_survey():
surveys=db(db.survey.code_edit==request.args[0]).select()
if not surveys:
session.flash='survey not found'
redirect(URL('index'))
return surveys[0]
def __take_survey():
surveys=db(db.survey.code_take==request.args[0]).select()
if not surveys:
session.flash='survey not found'
redirect(URL('index'))
return surveys[0]
ERROR:
Error ticket for "SurveyAppFlourish"
Ticket ID
127.0.0.1.2017-09-23.04-40-15.58fadb34-fbc0-4064-b9e1-ecc67362eafa
<type 'exceptions.IndexError'> list index out of range
Version
web2py™
Version 2.15.3-stable+timestamp.2017.08.07.12.51.45
Python
Python 2.7.12: C:\Python27\python.exe (prefix: C:\Python27)
Traceback
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Traceback (most recent call last):
File "C:\Users\Mudassar\PycharmProjects\web2pydemoproject\web2py\gluon\restricted.py", line 219, in restricted
exec(ccode, environment)
File "C:/Users/Mudassar/PycharmProjects/web2pydemoproject/web2py/applications/SurveyAppFlourish/controllers/survey.py", line 299, in <module>
File "C:\Users\Mudassar\PycharmProjects\web2pydemoproject\web2py\gluon\globals.py", line 409, in <lambda>
self._caller = lambda f: f()
File "C:/Users/Mudassar/PycharmProjects/web2pydemoproject/web2py/applications/SurveyAppFlourish/controllers/survey.py", line 88, in take
survey=__take_survey()
File "C:/Users/Mudassar/PycharmProjects/web2pydemoproject/web2py/applications/SurveyAppFlourish/controllers/survey.py", line 45, in __take_survey
surveys=db(db.survey.code_take==request.args[0]).select()
IndexError: list index out of range
错误是在surveys=db(db.survey.code_edit==request.args[0]).select()
'request.args'是一个空列表或空字符串。你不能得到空的第零索引。我建议先检查request.args的存在性,然后再尝试索引它。 – JacobIRR