you should check the value of len(postdata)
if len(postdata)>0:
         postdata=postdata[0]
   do someting if title == postdata.titel else something

在 2015年2月25日星期三 UTC+8上午4:29:46,tensio写道:
>
> Hi Guys,
>
> currently I'm working on a website with web.py and today I found an 
> strange error. 
> postdata = db.select("blog_article", where="id=$titleid", vars=locals())
>         postdata = postdata[0]
>         if title == postdata.titel:
>
> I get this error: 
>
>   File "app.py", line 163, in GET
>
>     postdata = postdata[0]
>
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/utils.py",
>  
> line 684, in __getitem__
>
>     raise IndexError, str(i)
>
> IndexError: 0
>
> So it seems to be a problem with the [0] thing. But I use the same code 
> for another db call:
> user = db.select('user', where="id=$userid", vars=locals())[0]
> where I get no error at all. 
>
> The funny thing is, with the postdata[0] thing I get my desired result, 
> but I keep getting the error. 
> What is wrong?
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to