My view function is as such:

def view():
    postid = request.args(0)
    post = db(db.blogPost.id == postid).select()[0]
    db.blogComment.post.default = postid
    commentForm = SQLFORM(db.blogComment)
    if commentForm.process().accepted:
        response.flash = 'Comment accepted'
    elif commentForm.errors:
        response.flash = 'Error posting comment.'
    return dict(post=post, commentForm=commentForm)

So posts are called with the url domain.com/app/controller/view/12 (12 
being the post ID). When trying to call a non-existent post ID I get the '<type 
'exceptions.IndexError'> list index out of range' error ticket.

I figured this was working as intended for troubleshooting purposes.

On Saturday, March 3, 2012 3:31:03 PM UTC-8, Anthony wrote:
>
> Sounds like an error in your code -- I assume you have a URL arg (or var) 
> being used to index a list, and you're going beyond the length of the list. 
> That's not a 404 error. If you want, you can explicitly raise a 404 error 
> in that case, but your code will have to check the id value and make sure 
> it is valid before attempting to use it.
>
> Note, you can create custom 404 and 500 error pages (static or dynamic) 
> using routes_on_error in routes.py: 
> http://web2py.com/books/default/chapter/29/4#Routes-on-error. 
>
> Anthony
>
> On Saturday, March 3, 2012 4:04:05 PM UTC-5, HittingSmoke wrote:
>>
>> I'm learning Python and web2py together (I know, not recommended but 
>> I'm having fun) by writing a small and simple blog. 
>>
>> I've run into a problem with 404s. When my app tries to pull up an 
>> invalid blog ID I get a 'list index out of range' error ticket. 
>> Ideally these should be 404 pages. Same goes for invalid controller 
>> errors. 
>>
>> I tried searching both the book and Google for info about setting up 
>> 404s for these types of situations but I'm not coming up with anything 
>> relevant. 
>>
>> Is there a standard practice for 404 pages in web2py when dealing with 
>> non-existent data errors?
>
>

Reply via email to