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

开发 后端
以下的文章主要是介绍的是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二维数组在创建过程中步骤详解


 

责任编辑:佚名 来源: 互联网
相关推荐

2010-03-22 19:11:55

Python连接

2010-03-25 09:38:03

Eclipse开发Py

2010-03-17 10:01:12

Python安装

2010-03-26 18:51:51

Python作用域

2010-03-22 09:54:38

Python开发环境

2010-06-01 15:54:46

MySQL-pytho

2010-03-19 14:59:00

python Stri

2010-03-24 18:00:30

Python中文转换u

2010-03-17 12:20:15

Python Libr

2010-03-30 11:29:24

Oracle备份

2010-03-23 18:20:26

Python os.g

2010-04-09 16:26:53

Oracle join

2010-03-17 15:58:08

Python环境

2010-03-25 13:05:00

Python执行代码

2010-05-13 13:49:09

MySQL数据库

2010-03-26 16:17:24

Python嵌入

2010-03-17 17:06:10

python脚本语言

2010-05-24 09:24:15

MySQL 备份

2010-04-21 12:35:01

Oracle导入

2010-04-27 09:28:55

绑定变量
点赞
收藏

51CTO技术栈公众号