zoukankan      html  css  js  c++  java
  • 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,截图如下

    • 设置/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

    • 重启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

    整个python CGI配置流程结束

  • 相关阅读:
    CSS部分
    css基础
    css初探
    html表单
    mysql视图 触发器 事物 函数 存储过程
    pymysql
    mysql数据备份与操作
    html基础
    mysql 索引
    tuple,list,dict,set用法
  • 原文地址:https://www.cnblogs.com/levcon/p/10794849.html
Copyright © 2011-2022 走看看