如果你在Python安装笔记的实际应用方面有一些不清楚的地方,或是你是在Python安装笔记这方面的新手,你可以浏览我们的文章,希望会对你有所收获,以下是文章相关内容的详细介绍。
以下步骤是自己配置过程一些记录。希望能对想使用mod_python的人有点帮助。另外请注意测试代码的缩进。
1.下载个新版 (注意版本问题apache和python版本)
2.拷到linux机器上,下面在命令行执行Python安装笔记:
- tar -zxvf mod_python-3.3.1.tgz
- cd mod_python-3.3.1
- ./configure --with-apxs=/usr/local/apache/bin/apxs
配置apxs目录
- ./configure --with-python=/usr/bin/python2.5
配置本地python
- make
- make install
3.这些编译完了,会在apache/modules/目录下生成mod_python.so,大概3M左右。
4.配置apache的http.conf
- LoadModule python_module modules/mod_python.so
- <Directory "/usr/modpython">
能用apache访问的目录
- #AddHandler mod_python .py
- SetHandler mod_python
- PythonHandler mod_python.publisher
- PythonDebug On
- </Directory>
5.测试在/usr/modpython/目录下新建一个test.py
- #coding:gb2312
- def index(req):
- req.write("hello,world!")
- return
6.运行Python安装笔记,启动apache没有错误后,#p#
7.定义其他方法:
- #coding:gb2312
- def index(req):
- req.write("hello,world!")
- return
- def hello(req):
- req.write("hello!!!")
- return
8.传递参数
- def get(req,name=""):
- if name:
- req.write("参数:"+name);
- else:
- req.write("no param.");
- return
POST表单一样,只要参数名写对就行。
9.python包在当前目录下建立一个包,然后在test.py导入时候会出错,找不到包。后来修改了下方法
- import os,sys
- sys.path.append(os.path.dirname(__file__))
把当前目录加入到sys.path中import 自己的包
【编辑推荐】
- Python字符串中字符的大写与小写的变化
- PythonS60手机中搭建手机运行平台的五个步骤
- Python数组中实际应用的数据结构的操作方案
- Python字符串在实际操作搜索与替换
- Python二维数组在创建过程中步骤详解