1, http://www.apache.org/dist/httpd/modpython/win/3.3.1/
下载mod_python-3.3.1.win32-py2.5-Apache2.2.exe
2, http://www.python.org/download/releases/2.5.4/
下载python-2.5.4.msi
3, http://www.djangoproject.com/download/
下载Django-1.0.2-final.tar.gz
4, http://sourceforge.net/projects/mysql-python/
下载MySQL-python-1.2.2.win32-py2.5.exe
二,安装
1,安装python2.5
2,安装mod_python-3.3
3,安装Django-1.0
将Django-1.0.2-final.tar.gz解压到python的安装目录下(本例为E:\Python25\Django),命令行进入E:\Python25,执行“python Django/setup.py install” ,Django即被安装到E:\Python25\Lib\site-packages\django下(E:\Python25\Django可删除)。
4,安装MySQL-python-1.2
(使python支持MySQL数据库)
三,配置
1,新建项目
命令行进入E:\Python25\Lib\site-packages\django\bin,执行“django-admin.py startproject myproj”,新建名为myproj的项目。
2,新建py文件
在E:\Python25\Lib\site-packages\django\bin\myproj目录下新建hello.py:
from django.http import HttpResponse def index(request): return HttpResponse('Hello, Django! so hard *_*')
3,配置apache的httpd.conf
添加LoadModule python_module modules/mod_python.so
添加
<Location "/"> SetHandler python-program PythonPath "['E:/Python25/Lib/site-packages/django/bin']+sys.path" PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE myproj.settings PythonInterpreter inves PythonDebug Off </Location>
4,修改urls.py文件
修改E:\Python25\Lib\site-packages\django\bin\myproj目录下的urls.py:
from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^$', 'myproj.hello.index'), )
四,运行
重启apache服务,访问http://localhost/,即可看到以下信息:
Hello, Django! so hard *_*
五 ,mysql
1) 文件"__init__":
from sets import ImmutableSet
class DBAPISet(ImmutableSet):
替换成
class DBAPISet(frozenset)
2) 文件"converters.py":
删除:from sets import BaseSet, Set
3) 文件 "converters.py",
把 "Set" 改成 "set" (一共两处):
line 48: return set([ i for i in s.split(',') if i ])
line 128: set: Set2Str,
4)把mysql/lib下面的libmysql.dll放入到/python/Lib/site-packages/文件夹下面
5)配置setting文件的数据库连接信息:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'mysql', # Or path to database file if using sqlite3. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': 'mysql密码', # Not used with sqlite3. 'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '3306', # Set to empty string for default. Not used with sqlite3. } }
配置完成