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

这是响应 404 的方式bottle framework。但是在 404 上,我想重定向到特定的 url,比如http://abc.com/。可能吗?

4

3 回答 3

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

编辑我不是 100% 确定这可以做到,我现在不能测试它,但我会稍后测试它并更新答案,除非你打败我。

于 2011-01-16T16:22:26.780 回答
3
    @app.error(404)
    def error(err):
        bottle.response.status = 303 
        bottle.response.header['Location'] = '/' 
于 2011-06-21T07:53:00.970 回答
-3
import urllib
url = urllib.urlopen('www.google.com/testing') #a 404 address
if url.code == 404:
    url = urllib.urlopen('www.google.com')

创建 urlobject 时, .code 实例返回页面的代码,

于 2010-11-26T16:32:36.137 回答