TIL

Today I Learned. 知ったこと、学んだことを書いていく

redirectする - bottle

bottleでリダイレクトをする方法

/abcにアクセスしたら、/defにリダイレクトしたい

from bottle import route, run
from bottle import redirect


@route('/abc')
def test1():
    redirect('/def')


@route('/def')
def test2():
    return 'defのページ'


run(host='localhost', port=3000, debug=True, reloader=True)
  • redirectをインポート
  • redirect(リダイレクト先のURL)でリダイレクトできる

/abcにアクセスすると、/defに飛ばされて、「defのページ」って表示された

/abc?name=fafie;afjiekafjdif;ejgnieaojfeとかのときに使えるかな?

参考文献