apache与mod_python通过publisher构建python运行环境
1.环境:apache2.0、mod_python3.3.12.在Apache2/conf/httpd.conf最后添加:
Include conf.d/*.conf
3.创建Apache2/conf.d/mod_python.conf,内容如下:
LoadModule python_module "modules/mod_python.so"
AddHandler python-program py
Alias /active/oa "D:/Program Files/Apache Group/Apache2/htdocs/active/py"
<Directory "D:/Program Files/Apache Group/Apache2/htdocs/active/py">
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
注:D:/Program Files/Apache Group/Apache2为本人Apache的安装目录,htdocs/active/py为python脚本和页面所在目录。
确保modules目录下存在mod_python.so。
4.创建表单处理脚本htdocs/active/py/form.py,内容如下:
import smtplib
from mod_python import apache
WEBMASTER = "webmaster" # webmaster e-mail
SMTP_SERVER = "localhost" # your SMTP server
def email(req, name, email, comment):
req.content_type = "text/plain"
s = """/
<html>
hello %s;<br>
from %s;<br>
comment %s;
</html>""" % (name,email,comment)
return s
5.创建提交表单页面htdocs/active/pyform.htm,内容如下:
<html>
请填写下面的回馈表单:
<form action="form.py/email" method="POST">
用户名: <input type="text" name="name"><br>
电子邮件: <input type="text" name="email"><br>
意见: <textarea name="comment" rows=4 cols=20></textarea><br>
<input type="submit">
</form>
</html>
页:
[1]