安装Apache
https://blog.csdn.net/weixin_41865104/article/details/89450909
访问 .py 的Python脚本文件需要配置apache2.conf文件
cd /etc/apache2
sudo vi apache2.conf
apache2.conf文件末尾添加
AddHandler cgi-script .cgi .pl .py
编写脚本simple.py,并将脚本放置/var/www/cgi-bin/中,同时赋予777权限
#!/usr/bin/python
#coding: utf-8
print 'Content-type: text/plain'
print
#打印空行,以结束首部
print 'Hello, world!'
print
print 'This a simple example'
红色框部分必不可少
#Apache下Python的CGI编程
#关于text/html和 text/plain
text/html的意思是将文件的content-type设置为text/html的形式,浏览器在获取到这种文件时会
自动调用html的解析器对文件进行相应的处理。
text/plain的意思是将文件设置为纯文本的形式,浏览器在获取到这种文件时并不会对其进行处理。
#将simple.py文件中text/plain修改text/html测试一下