Code Source https://www.shiyanlou.com/courses/552, understand it, comment
#-*-coding:utf-8-*-ImportBasehttpserverclassRequestHandler (basehttpserver.basehttprequesthandler):" "process the request and return to the page" " #page TemplatesPage =" "" " #processing a GET request, the function do_get () is required in Basehttprequesthandler, and it looks for Do_get to handle the GET request. See basehttpserver.py (http://my.oschina.net/hevakelcj/blog/372923) defDo_get (self): Self.send_response (200)#These are all methods in Basehttprequesthandler.Self.send_header ("Content-type","text/html") Self.send_header ("Content-length", str (len (self). Page)) Self.end_headers () Self.wfile.write (self). Page)#----------------------------------------------------------------------if __name__=='__main__': ServerAddress= ("', 8080) Server=basehttpserver.httpserver (serveraddress, RequestHandler) server.serve_forever ()
2.
Python for simple Web server parsing