8

This is my code:

from http.server import HTTPServer, BaseHTTPRequestHandler

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write(b'some text')

def redirect(location):
    # redirect

server = HTTPServer(('localhost', 1111), Handler)
server.serve_forever()

How can I write a function to redirect from a path to another?

1 Answers1

16

I think my response is too late, but for the others, here a solution.

self.send_response(302)
self.send_header('Location', url)
self.end_headers()
elhostis
  • 1,067
  • 14
  • 32