Randy
Randy

Reputation: 617

Python Error in Web.Py from a Newbie

I am a newbie in Python & web.py so excuse my ignorance. I had a script for a web page that was working, and then randomly stopped working. I've been at it for a few days and cant seem to figure the issue out.

I keep getting the following error:

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'

Here is my Python script:

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()

The template is stored in a 'templates' folder and is as follows:

$def with (form,tweets_index)
$for tweets in tweets_index:
        $tweets.tweet
        $tweets.normalized_tweet
<form action="/update/$tweets.tweet_id" method="post">
    $:form.render()
    <input type="submit" value="update"/>
</form>

If I change the name of the index page to something else, then that is what shows up in the error. Please help!

Upvotes: 1

Views: 2939

Answers (1)

Otto Allmendinger
Otto Allmendinger

Reputation: 28268

You don't have a class index with a GET method

Upvotes: 5

Related Questions