Python安裝筆記的實際應(yīng)用的九種步驟介紹
如果你在Python安裝筆記的實際應(yīng)用方面有一些不清楚的地方,或是你是在Python安裝筆記這方面的新手,你可以瀏覽我們的文章,希望會對你有所收獲,以下是文章相關(guān)內(nèi)容的詳細介紹。
以下步驟是自己配置過程一些記錄。希望能對想使用mod_python的人有點幫助。另外請注意測試代碼的縮進。
1.下載個新版 (注意版本問題apache和python版本)
2.拷到linux機器上,下面在命令行執(zhí)行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.傳遞參數(shù)
- def get(req,name=""):
- if name:
- req.write("參數(shù):"+name);
- else:
- req.write("no param.");
- return
POST表單一樣,只要參數(shù)名寫對就行。
9.python包在當(dāng)前目錄下建立一個包,然后在test.py導(dǎo)入時候會出錯,找不到包。后來修改了下方法
- import os,sys
- sys.path.append(os.path.dirname(__file__))
把當(dāng)前目錄加入到sys.path中import 自己的包
【編輯推薦】
- Python字符串中字符的大寫與小寫的變化
- PythonS60手機中搭建手機運行平臺的五個步驟
- Python數(shù)組中實際應(yīng)用的數(shù)據(jù)結(jié)構(gòu)的操作方案
- Python字符串在實際操作搜索與替換
- Python二維數(shù)組在創(chuàng)建過程中步驟詳解