我是Python&;网页.py原谅我的无知。我有一个网页的脚本在工作,然后随机停止工作。我已经做了几天了,似乎还没弄清楚这个问题。在
我一直收到以下错误:127.0.0.1:49664 - - [05/Jul/2012 23:58:42] "HTTP/1.1 GET /" - 500 Internal Server Error
127.0.0.1:49664 - - [05/Jul/2012 23:58:43] "HTTP/1.1 GET /favicon.ico" - 404 Not Found
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\web\application.py", line 239, in process return >self.handle()
File "C:\Python27\lib\site-packages\web\application.py", line 230, in handle return >self._delegate(fn, self.fvars, args)
File "C:\Python27\lib\site-packages\web\application.py", line 419, in _delegate cls = >fvars[f]
KeyError: u'index'
下面是我的Python脚本:import web
from web import form
db = web.database(dbn='mysql', user='dbuser', pw='dbuser', db='database')
render = web.template.render('templates/')
urls = (
'/', 'index',
'/update/(\d+)', 'update'
)
app = web.application(urls, globals())
myform = form.Form(
form.Radio('sentiment',[('1','Positive'),('3','Neutral'),('2','Negative'),('4','SPAM')],description='Sentiment',))
def insert_sentiment(id, sentimentvar):
db.update('tweets', sentiment=sentimentvar, where="tweet_id=$id", vars=locals())
class update:
def GET(self):
tweets_index = db.select('tweets', where='sentiment is null', order='RAND()', limit=1)
form = myform()
return render.index(form, tweets_index)
raise web.seeother('/')
def POST(self, id):
form = web.input()
insert_sentiment(id, form.sentiment)
raise web.seeother('/')
if __name__=="__main__":
web.internalerror = web.debugerror
app.run()
模板存储在“templates”文件夹中,如下所示:
^{pr2}$
如果我将索引页的名称更改为其他名称,则错误中显示的就是这个名称。请帮忙!在