python+mod_python+django搭建詳解_藍邦商貿 <script src="/include/dedeajax2.js" type="text/javascript"></script> <script type="text/javascript"> <!-- function CheckLogin(){ var taget_obj = document.getElementById('_ajax_feedback'); myajax = new DedeAjax(taget_obj,false,false,'','',''); myajax.SendGet2("/member/ajax_feedback.php"); DedeXHTTP = null; } function checkSubmit(){ if(document.feedback.msg.value!='') document.feedback.submit(); else alert("評論內容不能爲空!"); } function postBadGood(ftype,fid) { var taget_obj = document.getElementById(ftype+fid); var saveid = GetCookie('badgoodid'); if(saveid != null) { var saveids = saveid.split(','); var hasid = false; saveid = ''; j = 1; for(i=saveids.length-1;i>=0;i--) { if(saveids[i]==fid && hasid) continue; else { if(saveids[i]==fid && !hasid) hasid = true; saveid += (saveid=='' ? saveids[i] : ','+saveids[i]); j++; if(j==10 && hasid) break; if(j==9 && !hasid) break; } } if(hasid) { alert('您剛纔已表決過了喔!'); return false;} else saveid += ','+fid; SetCookie('badgoodid',saveid,1); } else { SetCookie('badgoodid',fid,1); } myajax = new DedeAjax(taget_obj,false,false,'','',''); myajax.SendGet2("/plus/feedback.php?aid="+fid+"&action="+ftype+"&fid="+fid); DedeXHTTP = null; } function postDigg(ftype,aid) { var taget_obj = document.getElementById('newdigg'); var saveid = GetCookie('diggid'); if(saveid != null) { var saveids = saveid.split(','); var hasid = false; saveid = ''; j = 1; for(i=saveids.length-1;i>=0;i--) { if(saveids[i]==aid && hasid) continue; else { if(saveids[i]==aid && !hasid) hasid = true; saveid += (saveid=='' ? saveids[i] : ','+saveids[i]); j++; if(j==20 && hasid) break; if(j==19 && !hasid) break; } } if(hasid) { alert("您已經頂過該帖,請不要重複頂帖 !"); return; } else saveid += ','+aid; SetCookie('diggid',saveid,1); } else { SetCookie('diggid',aid,1); } myajax = new DedeAjax(taget_obj,false,false,'','',''); var url = "/plus/digg_ajax.php?action="+ftype+"&id="+aid; myajax.SendGet2(url); DedeXHTTP = null; } function getDigg(aid) { var taget_obj = document.getElementById('newdigg'); myajax = new DedeAjax(taget_obj,false,false,'','',''); myajax.SendGet2("/plus/digg_ajax.php?id="+aid); DedeXHTTP = null; } --> </script>
python+mod_python+django搭建詳解
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } A:link { color: #0000ff; so-language: zxx } -->
全手動安裝開發環境:Apache+Python+PHP+Mysql支持Django框架
該開發環境方案均選用開源服務器及程序支持。
操作系統:
Windows XP
pro
服務器:
Apache
2.2
程序:
Python2.5、PHP5.2.6
數據庫:
Mysql5.0、SQLite3
框架:
Django1.0
所需要程序:
Python2.5安裝文件,
Apache2.2.49for Windows x86安裝文件:apache_2.2.9-win32-x86-openssl-0.9.8h-r2
安裝步驟:
1.Python2.5:
一步步確認就可以了,我的安裝目錄是c:/python25。然後配置環境變量PATH屬性,這樣可以保證在任何文件夾下使用命令行工具執行python命令,方法是:開始菜單>右鍵我的電腦>屬性>高級>環境變量,找到Path一項,加入“C:/Python25;”,重啓電腦。
Tips:
注意安裝時候要選擇使用權限爲All Users
2.Django1.0:
>>> import django
>>> django.VERSION
你應該會看到類似(1,0,final)之類的版本信息,恭喜強大好用的python framework django已經安裝成功了!
下載以後直接安裝就可以了,我的安裝目錄在c:/apache2.2
Tips:各個文件都安裝在了c盤下是爲了便於配置,沒有特別要求。另同python安裝要選擇使用權限爲All
Users。
Important Note for Windows users, PLEASE
READ!!!
1. This script does not attempt to modify Apache
configuration,
you must do it manually:
Edit
C:/Apache2.2/conf/httpd.conf,
find where other LoadModule lines are and add
this:
LoadModule python_module modules/mod_python.so
2. Now test your
installation using the instructions at this
link:
http://www.modpython.org/live/current/doc-html/inst-testing.html
讓apache支持php,此操作可以參考php5中文手冊,解壓php文件到C:/PHP,把php.ini配置好,修改path路徑增加c:/php;,然後再打開httpd.conf寫入
# 對 PHP 5 用這兩行:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
# 配置 php.ini 的路徑
PHPIniDir "C:/php"
重啓。OK,新建一個test.php在網站根目錄下C:/Apache2.2/htdocs,用phpinfo()測試。
PS:爲了讓php支持cookie及session需要做兩個修改在php.ini上,session.save_path
= "c:/php/session_tmp"及session.use_cookies =
1,如果需要使用phpmyadmin設置mysql的話就一定要做這些設置了
6.MySQL5:
7. 安裝 mysql_python : 直接下一步就可以完成。
8. 讓 apache 支持對 django框架的支持:
python django-admin.py startproject myproject
__init__.py
manage.py
settings.py
urls.py
四個文件,然後修改httpd.conf文件,在最後加入
Alias /mysite
C:/django/myproject
#斜體部分沒有測試成功
AddHandler mod_python .py
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
PythonDebug On
PythonPath "['C:/django'] + sys.path"
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
1.
安裝django
運行-cmd打開命令提示框
輸入 cd
C:/Python25指向python目錄,否則不能執行python命令
python setup.py install
進行安裝,會出現一系列的copy信息;
2.
先簡單的測試一下。
命令提示符下,輸入:python
然後輸入import
django
然後輸入django.VERSION
我看到的是這樣的:......
3.
在C:/Python25/Scripts可以看到django-admin.py了
4. 在c:/創建django目錄,copy
django-admin.py到該目錄
執行 django-admin.py startproject
myproject
創建了myproject
5. cd C:/python25 回到這裏
執行 python
c:/django/myproject/manage.py runserver
可以看到類似
Django version 0.9.1(SVN),
using settings 'myproject.settings'
Development server is running at
http://127.0.0.1:8000/
Quit the server with CONTROL-C or
CTRL-BREAK.
說明一切正常啓動
6. 訪問 http://localhost:8000/mysite可以看到 welcome to
Django了#加入8000和mysite沒有成功,但當改爲myproject時測試成功。
7. 在httpd.conf中寫入
Alias
/mysite C:/django/myproject
AddHandler mod_python .py
SetHandler
python-program
PythonHandler django.core.handlers.modpython
SetEnv
DJANGO_SETTINGS_MODULE myproject.settings
PythonDebug On
PythonPath
"['C:/django'] + sys.path"
Options Indexes FollowSymLinks
AllowOverride
None
Order allow,deny
Allow from all
即可以使用http://localhost/mysite/
訪問了
##mysite沒有測試成功 但myproject成功
8. hello
world
在myproject目錄創建 helloworld.py
from django.http import
HttpResponse
def index(request):
return HttpResponse('Hello,
World!')
然後打開urls.py修改urlpatterns,加入一個pattern
(r'^mysite/',
'myproject.helloworld.index'),
9.
重啓apache,打開http://localhost/mysite/
看到hello,world
- 最新評論 查看所有評論
-
<script src="/plus/feedback_js.php?aid=3" type="text/javascript"></script>
- 發表評論 查看所有評論
-
- 推薦內容