import BaseHTTPServer, sys class Handler(BaseHTTPServer.BaseHTTPRequestHandler): # invoked when HTTP GET request received def do_GET(self): if self.path != '/': # only respond to one URI, namely / self.send_error(404, 'File not found') return self.send_response(200) # this means OK self.send_header('Content-type','text/html') # keyword/pair line in response header self.end_headers() # no more header lines, but insert the '\r\n' # after this, we have the part that creates HTML # that will be the content (page) being served up line = '

%s

' # very simple HTML line = line % 'Hello World' self.wfile.write(line) # write content of page httpd = BaseHTTPServer.HTTPServer( ('',8100), Handler ) print "serving at port 8100" httpd.handle_request() # program handles just one request