如何重定向到404上的特定URL [英] how to redirect to particular url on 404

查看:218
本文介绍了如何重定向到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.

这篇关于如何重定向到404上的特定URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆