Python学习笔记-Python CGI 环境搭建

Web server programming environment setup(windows)

Python3.x built-in cgi-server is strongly recommanded

Python学习笔记-Python CGI 环境搭建

 I use Python 3.8.1

1. At first, make a directory somewhere named 'www', where you should make one more directory named 'cgi-bin'.For instance, I build it in the root directory of disk D as shown in the screenshot below.

Python学习笔记-Python CGI 环境搭建

2. After the directories made, come to directory 'C:\Windows\System32' for cmd.exe,then right-click and choose 'Run as  an Administrator', 

Python学习笔记-Python CGI 环境搭建

 

Python学习笔记-Python CGI 环境搭建

3. Input command D:——>cd D:\PyCharm Community Edition 2019.2.4\www——>python -m http.server --cgi PORTNUMBER( unused ports such as 8001)

Python学习笔记-Python CGI 环境搭建

4.Input 'localhost:PORTNUMBER' in browser address field to test if the CGI service is activated.

Python学习笔记-Python CGI 环境搭建

 

make a python file(.py) under the 'cgi-bin' directory, the code is shown below

Python学习笔记-Python CGI 环境搭建

Python学习笔记-Python CGI 环境搭建

Input in the browser address field as below:

Python学习笔记-Python CGI 环境搭建

Inspiration from Chinese blog https://baijiahao.baidu.com/s?id=1608396131352808822&wfr=spider&for=pc