First make sure Python is installed, I have the 2.x version, yes, my operating system is WIN7, in fact, for Python, what operating system is not important. Python has a simple HTTP server built-in, with just one command line underneath it, and an HTTP server up:
Python-m Simplehttpserver 80
The following 80 ports are optional and do not fill with the default port of 8000. Note that this will set the current folder as the default Web directory and try typing the native address in the browser:
Http://localhost:80
If the current folder has a index.html file, the file is displayed by default, otherwise all files under the directory are displayed as a list of files. This has achieved the most basic purpose of file sharing, you can make a script, and then create a shortcut, you can easily start sharing the file. If there are more needs, can be customized according to their own needs, specific see the Official document Simplehttpserver, or directly read the source code. I copy a paragraph for easy reference:
Import Simplehttpserverimport socketserverport = 8000Handler = SIMPLEHTTPSERVER.SIMPLEHTTPREQUESTHANDLERHTTPD = Socketserver.tcpserver (("", PORT), Handler) print "Serving at PORT", Porthttpd.serve_forever ()
If you want to change the port number, you can use the following command:
If you just want this HTTP server to serve your local environment, then you need to customize your Python program, here's an example:
Import sys import basehttpserver from simplehttpserver import Simplehttprequesthandler Handlerclass = Simplehttprequesthandler ServerClass = Basehttpserver.httpserver Protocol = "http/1.0" if sys.argv[1:]: port = Int (sys.argv[1]) Else: Port = 8000 Server_address = (' 127.0.0.1 ', port) handlerclass.protocol_version = Protocol httpd = ServerClass (server_address, Handlerclass)
Note: All of these things can work under Windows or Cygwin.