Home  >  Article  >  Backend Development  >  Python3’s simple way to build your own server

Python3’s simple way to build your own server

不言
不言Original
2018-06-04 11:05:242337browse

This article mainly introduces how to simply build your own server in Python3. It has certain reference value. Now I share it with you. Friends in need can refer to

WEB development. Let’s start by building a Start with a simple server. Python comes with a service module, and python3 is very different from python2.

In the Python2.6 version, there will be a directory under /usr/bin/lib/python2.6/ There are two files: BaseHTTPServer.py, SimpleHTTPServer.py, and CGIHTTPServer.py.

But in Python3.4, there are no above three files, but they are closed in /usr/bin/python3.4/ http/server.py file.

So in the python2 version, if you want to start the service that comes with python, enter in the doc window:

python -m CGIHTTPServer 8081

The 8081 port number can be set by yourself. The default port number is 8080

In python3, because

BaseHTTPServer.py, SimpleHTTPServer. py, the CGIHTTPServer.py module is merged into the server module, so the code to start the server has also been changed, which is:

<strong>python -m http.server 8081</strong>

After starting correctly, the screenshot is as follows :

Enter localhost:port number in the browser to access

Related recommendations:

Easy way to create httpServer with Python3

The above is the detailed content of Python3’s simple way to build your own server. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn