how to redirect to particular url on 404

孤街醉人 提交于 2019-12-06 11:33:44
@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 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.

    @app.error(404)
    def error(err):
        bottle.response.status = 303 
        bottle.response.header['Location'] = '/' 
import urllib
url = urllib.urlopen('www.google.com/testing') #a 404 address
if url.code == 404:
    url = urllib.urlopen('www.google.com')

When a urlobject is created the .code instance returns the code of the page,

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!