首页论坛搜索维客商业
名佳名流太平家园王府农场北亚花园蓬莱苑天通苑
亚北望京望都家园北苑家园温泉花园宏福苑回龙观

把Python嵌入apache

首页 » 论坛 » 维客 » 看图学英语 » 视频 » 日语 » 图像

下文针对 Fedora /CentOS 系统

[编辑]

1 安装 mod_python

sudo yum install mod_python
[编辑]

2 配置 Apache

  1. 一般使用 Pulisher Handler,它允许纯 Python 脚本
  2. 也可以使用 PSP(Python Server Pages),它类似于 PHP 把代码嵌入 HTML 中。
[编辑]

3 The Publisher Handler

cp /etc/httpd/conf.d/python.conf /etc/httpd/conf.d/python.conf_orig
cat /dev/null > /etc/httpd/conf.d/python.conf
vi /etc/httpd/conf.d/python.conf
LoadModule python_module modules/mod_python.so

<Directory /var/www/html/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
  AddHandler mod_python .py
  PythonHandler mod_python.publisher
  PythonDebug On
</Directory>

/etc/init.d/httpd restart

测试代码:

vi /var/www/html/test.py

def index(req):
  return "Test successful";
[编辑]

4 The PSP Handler

cp /etc/httpd/conf.d/python.conf /etc/httpd/conf.d/python.conf_orig
cat /dev/null > /etc/httpd/conf.d/python.conf
vi /etc/httpd/conf.d/python.conf
LoadModule python_module modules/mod_python.so

<Directory /var/www/html/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
  AddHandler mod_python .psp
  PythonHandler mod_python.psp
  PythonDebug On
</Directory>

/etc/init.d/httpd restart

谷歌广告

最新词条

论坛 » 导航 » 维客 » KWE » 编辑 » 记录 » 打印 » 上传 » 下载

孔晖 2011-01-03 Power By KWE