@error(404)
def error404(error):
return 'Nothing here, sorry'
这是响应 404 的方式bottle framework
。但是在 404 上,我想重定向到特定的 url,比如http://abc.com/。可能吗?
@error(404)
def error404(error):
return 'Nothing here, sorry'
这是响应 404 的方式bottle framework
。但是在 404 上,我想重定向到特定的 url,比如http://abc.com/。可能吗?
@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% 确定这可以做到,我现在不能测试它,但我会稍后测试它并更新答案,除非你打败我。
@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')
创建 urlobject 时, .code 实例返回页面的代码,