重定向在 turbogears 2.3 中抛出 "Resource was found at " 异常

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

当用户访问某个控制器并且满足条件时,我想将用户重定向到其他页面,但是当我尝试这样做时它抛出 "Resource was found at exception"。下面是我正在尝试的代码。

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

当 kw['u']==1 时,它并没有带我到索引页面,而是抛出上述错误。请建议我如何进行。

redirect 抛出 HTTPFound 异常,因此您在 except 子句中捕获它。可能您想使 except 更具体或将 redirect 移出 try