我正在嘗試一個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