Redirect function with BaseHTTPRequestHandler
Asked Answered
D

1

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?

Dot answered 27/3, 2014 at 23:46 Comment(0)
S
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()
Sermon answered 10/7, 2014 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.