Use native Python developed Web server, entry level!
#!/usr/bin/python#-*-coding:utf-8-*-ImportOs#The OS module in the Python standard library contains common operating system featuresImportRe#Introducing Regular Expression ObjectsImportUrllib#used to encode URLs fromBasehttpserverImportHttpserver, Basehttprequesthandler#importing HTTP processing-related modules#custom handlers for handling HTTP requestsclassTesthttphandler (basehttprequesthandler):#Handling GET Requests defDo_get (self):#Get URL Print 'url=', Self.path#page Output Template stringTemplatestr =" "" "self.protocal_version='http/1.1' #Set Protocol versionSelf.send_response (200)#Setting the response status codeSelf.send_header ("Welcome","contect")#Setting the response headerself.end_headers () self.wfile.write (TEMPLATESTR)#Output Response Content #Start the service functiondefStart_server (port): Http_server= Httpserver (("', int (port)), Testhttphandler) Http_server.serve_forever ()#set up listening and receiving requests#os.chdir (' static ') #改变工作目录到 static directoryStart_server (8000)#Start the service, listen on port 8000
Python httpserver Server (beginner)