main.py592 chars23 lines
In the above code, we define a Handler
class which inherits from BaseHTTPRequestHandler
and where we implement the do_GET
method to handle the incoming HTTP GET request.
Inside this method, we first set the response status code to 200
and set the response header Content-type
to text/html
.
After that, we define the HTML content to be sent in the html_response
variable and send it to the client using the wfile
object.
Finally, we create an instance of HTTPServer
on the localhost and the specified port, and then start it using the serve_forever()
method.
gistlibby LogSnag