欢迎光临
我们一直在努力

Python安装笔记的实际应用的九种步骤介绍

如果你在Python安装笔记的实际应用方面有一些不清楚的地方,或是你是在Python安装笔记这方面的新手,你可以浏览我们的文章,希望会对你有所收获,以下是文章相关内容的详细介绍。

以下步骤是自己配置过程一些记录。希望能对想使用mod_python的人有点帮助。另外请注意测试代码的缩进。

1.下载个新版 (注意版本问题apache和python版本)

2.拷到linux机器上,下面在命令行执行Python安装笔记:


 
  1. tar -zxvf mod_python-3.3.1.tgz  
  2. cd mod_python-3.3.1  
  3. ./configure --with-apxs=/usr/local/apache/bin/apxs   

 

 配置apxs目录


 
  1. ./configure --with-python=/usr/bin/python2.5   

 

配置本地python


 
  1. make  
  2. make install 

3.这些编译完了,会在apache/modules/目录下生成mod_python.so,大概3M左右。

4.配置apache的http.conf


 
  1. LoadModule python_module modules/mod_python.so  
  2. <Directory "/usr/modpython"> 

 

 能用apache访问的目录


 
  1. #AddHandler mod_python .py  
  2. SetHandler mod_python  
  3. PythonHandler mod_python.publisher  
  4. PythonDebug On  
  5. </Directory> 

5.测试在/usr/modpython/目录下新建一个test.py


 
  1. #coding:gb2312  
  2. def index(req):  
  3. req.write("hello,world!")  
  4. return  

6.运行Python安装笔记,启动apache没有错误后,#p#

7.定义其他方法:


 
  1. #coding:gb2312  
  2. def index(req):  
  3. req.write("hello,world!")  
  4. return  
  5. def hello(req):  
  6. req.write("hello!!!")  
  7. return  

8.传递参数


 
  1. def get(req,name=""):  
  2. if name:  
  3. req.write("参数:"+name);  
  4. else:  
  5. req.write("no param.");  
  6. return  

POST表单一样,只要参数名写对就行。

9.python包在当前目录下建立一个包,然后在test.py导入时候会出错,找不到包。后来修改了下方法


 
  1. import os,sys  
  2. sys.path.append(os.path.dirname(__file__))  

 

 把当前目录加入到sys.path中import 自己的包

【编辑推荐】

  1. Python字符串中字符的大写与小写的变化
  2. PythonS60手机中搭建手机运行平台的五个步骤
  3. Python数组中实际应用的数据结构的操作方案
  4. Python字符串在实际操作搜索与替换
  5. Python二维数组在创建过程中步骤详解

 

赞(0) 打赏
未经允许不得转载:九八云安全 » Python安装笔记的实际应用的九种步骤介绍

评论 抢沙发