@error(404)
def error404(error):
return 'Nothing here, sorry'
これは、 で 404 に応答する方法bottle framework
です。しかし、404 では、 http://abc.com/などの特定の URL にリダイレクトしたいと考えています。出来ますか?
@error(404)
def error404(error):
return 'Nothing here, sorry'
これは、 で 404 に応答する方法bottle framework
です。しかし、404 では、 http://abc.com/などの特定の URL にリダイレクトしたいと考えています。出来ますか?
@app.error(404)
def error(err):
bottle.response.status = 303
bottle.response.header['Location'] = '/'
@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%確信が持てず、今はテストできませんが、後でテストして答えを更新します。
import urllib
url = urllib.urlopen('www.google.com/testing') #a 404 address
if url.code == 404:
url = urllib.urlopen('www.google.com')
urlobject が作成されると、.code インスタンスはページのコードを返します。