0

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.

neeraj
  • 89
  • 2
  • 8

1 Answers1

0

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.

amol
  • 1,771
  • 1
  • 11
  • 15
  • thank you very much. Just wanted to know how can I import HTTPFound exception so that when this exception occurs, I can easily raise it. Currently I am using sys.exc_info()[0].__name__ to find the name of exception and then raising it. – neeraj May 09 '16 at 09:32
  • 1
    `from tg.exceptions import HTTPFound` – amol May 10 '16 at 06:47