1.序

要实现一个人脸识别登录项目是使用的知识。

CGI(Common Gateway Interface),叫做公共网关接口。CGI是Web 服务器运行时外部程序的规范,按CGI 编写的程序可以扩展服务器功能。

2.CGI服务器

2.1新建www目录(具体位置不限),www目录下新建cgi-bin目录,在cgi-bin下建python文件index.py,内容如下:

#!/usr/bin/python
#coding:utf-8
print('Content-type:text/html\n')#以上固定
print ('html标签')
...
print(''html标签'')

以上是python文件的头部,是固定的,具体的内容要写在头部以下。

2.2增加目录下所有*.py文件的可执行权限。

2.3在目录www中(注意:不是cgi-bin),开启命令行,执行如下命令:

python -m http.server --cgi 8001

2.4这样可执行python的服务器启动成功了,浏览器中输入url:

http://localhost:8001/cgi-bin/index.py

浏览器显示是就是index.py中输出的python内容。

2.5如报错403,则说明url中未包含python文件。

2.6接收html中form表单GET/POSt传值。

#!/usr/bin/env python
import cgi
form = cgi.FieldStorage()
name = form.getvalue("name", "world")#world是默认值
print("Content_type: text/plain\n")
print("Hello, {}!".format(name))