Pyhton配置CGI

CGI--common gateway interface 通用网关接口的意思,本文通过python的CGI来整体了解下CGI的配置和使用

CGI配置(Mac版)

  • 安装前提要装好apache,python等必要软件,本次只针对CGI的配置
进入apache2目录
/etc/apache2
编辑httpd.conf
vi httpd.conf
  • 取消注释LoadModule cgi_module libexec/apache2/mod_cgi.so,截图如下
    1399733-20190430110631930-461720982.png

  • 设置/Library/WebServer/CGI-Executables目录的权限
<Directory "/Library/WebServer/CGI-Executables">
    AllowOverride None
    Options ExecCGI    
    Order allow,deny
    Allow from all
</Directory>
  • 同时注释调
#<Directory />
# AllowOverride none
# Require all denied
#</Directory>
  • 取消注释AddHandler cgi-script .cgi,同时在末尾加上.py
    1399733-20190430110643593-1739986852.png

  • 重启apache2
sudo  apachectl restart 

添加CGI python文件测试

  • 进入刚才设置的目录/Library/WebServer/CGI-Executables
    建test.py,并授权chmod 777 test.py
#!/usr/bin/python
# -*- coding: UTF-8 -*-

print "Content-type:text/html"
print
print '<html>'
print '<head>'
print '<meta charset="utf-8">'
print '<title>Hello World - 我的第一个 CGI 程序!</title>'
print '</head>'
print '<body>'
print '<h2>Hello World! </h2>'
print '</body>'
print '</html>'
  • 通过浏览器访问http://localhost/cgi-bin/test.py
    1399733-20190430110655365-217476875.png

整个python CGI配置流程结束

转载于:https://www.cnblogs.com/levcon/p/10794849.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值