python-2.7http-redirectturbogears2

redirect is throwing a "Resource was found at " exception in turbogears 2.3


When a user is accessing a certain controller and if a condition is met, then i want to redirect user to some other page but when I'am trying that it throwing "Resource was found at exception". Below is the code which I'm trying.

@expose("sample.templates.show_id")
def show_id(self, **kw):
    try:
        if kw['u']==1:
            redirect ("/")
        else:
            groups = self.handle_u(kw['u'])
    except Exception as e:
        print str(e)
    return dict(groups=groups)

When the kw['u']==1, then it is not taking me to the index page, but throwing the mentioned error. Please suggest me how to proceed.


Solution

  • redirect throws an HTTPFound exception, so you are catching it in the except clause. Probably you want to make the except more specific or move the redirect  out of the try.