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>
-
发表评论
查看所有评论
-
-
推荐内容