Apache + CGI(Python)的简单实用WEB程序的开发
来源:互联网 发布:python 不显示warning 编辑:程序博客网 时间:2024/05/29 19:19
1.Apache + CGI的架构图
2.Apache + Python CGI的开发和配置方法
(1)安装apache
执行命令yum install httpd即可完成apache的安装,确保apache配置/etc/httpd/conf/httpd.conf中包含如下配置:
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"<Directory "/var/www/cgi-bin"> AllowOverride None Options +ExecCGI Order allow,deny Allow from all</Directory>AddHandler cgi-script .cgi .pl .py
备注:ScriptAlias指定了python cgi脚本的存放目录为/var/www/cgi-bin/,且用户访问的方式为http://ip:port/cgi-bin/XXX;<Directory "/var/www/cgi-bin">配置了cgi脚本目录的可执行权限;AddHandler cgi-script指令配置可以支持的cgi脚本文件的后缀。
(2)编写Python CGI脚本
举例来说,
#!/usr/bin/env python# -*- coding: utf-8 -*-"""Desc: python common cgiDate: 2017-11-23Author: xxxx"""import time#定义全局变量nowtime = ''def initData(): """用来获取填充html页面的数据 """ global nowtime nowtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())def genHtml2(): """生成HTML页面, 使用三个双引号,使Python中的HTML页面更美观 """ print 'Content-type:text/html' print print """<html> <head> <meta charset="utf-8"> <title>Python CGI DEMO程序</title> </head> <body> <h1>This is DEMO~~~~</h1> </body></html>"""def genHtml(): """生成HTML页面 """ print "Content-type:text/html" print print '<html>' print '<head>' print '<meta charset="utf-8">' print '<title>Python CGI DEMO程序</title>' print '</head>' print '<body>' print '<h2>当前时间为: %s</h2>' % nowtime print '</body>' print '</html>'def main(): """CGI入口 """ #初始化环境 initData() #生成页面 genHtml()if __name__ == '__main__': main()
备注:可以将该文件命名为xxx.cgi,xxx.py等等都是可以的。这个脚本可以成任何的脚本语言哦,例如perl,shell,C以及C++等等。
学习资料参考于:
http://www.runoob.com/python/python-cgi.html
阅读全文
0 0
- Apache + CGI(Python)的简单实用WEB程序的开发
- python CGI简单的web应用
- Python的Web开发环境之CGI(一)--Ubuntu
- 开发基于Apache服务器上的CGI程序
- 开发基于Apache服务器上的CGI程序
- Apache Web 服务器配置CGI程序,执行Python、Perl脚本
- apache运行CGI程序的配置
- apache运行CGI程序的配置
- apache运行CGI程序的配置
- apache支持python写的CGI
- Python CGI与Apache的配置
- Apache ab 的简单实用
- linux下简单的apache表单+c语言写cgi程序
- 简单实用Python程序
- python实用的程序(周期执行)
- WEB服务器:利用python CGI实现简单的微信后台服务器
- python的property简单实用
- 简单实用的Python计算器
- eclipse console 输出每行最大值和输出行问题
- python3 scrapy css选择器(Selectors) 用法
- iOS中如何实现单个页面支持横竖屏(其他页面只能竖屏)
- 字节、字、bit、byte的关系
- springmvc注入失败
- Apache + CGI(Python)的简单实用WEB程序的开发
- 输出两个整数的最大值
- 解决Dialog中有EditText时无法自动弹出输入的问题
- 4.11 import 语句
- Hadoop2.6.4搭建笔记
- Vue+Webpack引入Jquery第三方插件,jQuery is not defined 错误,解决方案
- js多余的内容显示省略号
- postman工具使用总结
- CVE-2017-8759 复现