Python bottle minimal redirect example

To redirect in bottle, use this snippet:

response.status = 303
response.set_header('Location', 'https://techoverflow.net')

303 is the HTTP response code See Other. In certain applications you might want to use 301 (permanent redirect) or 307 (temporary redirect) instead.

Full example:

#!/usr/bin/env python3
from bottle import route, run, response

@route('/')
def redirect():
    response.status = 303
    response.set_header('Location', 'https://techoverflow.net')

run(host='localhost', port=9000)