如何重定向到404上的特定URL

问题描述:

@error(404)
def error404(error):
    return 'Nothing here, sorry'

这是在瓶子框架中响应404的方法。但是在404上,我想重定向到特定的网址,例如 http://abc.com/

This is the way to response 404 in bottle framework. But On 404 I want to redirect to particular url say http://abc.com/. Is it possible?

@error(404)
def error404(error):
    from bottle import redirect
    # maybe test the error to see where you want to go next?
    redirect(new_url, 303) # HTTP 303 should be used in this case

EDIT 我不确定100%可以做到这一点,而且我现在无法测试,但我稍后会对其进行测试并更新答案,除非您击败我。

EDIT I'm not 100% sure this can be done, and I can't test it right now, but I'll test it later and update the answer unless you beat me to it.