环境:windows2008, apache2.2, python2.5, mod_python-3.3.1.win32-py2.5-Apache2.2, django-1.0.2_final
1、创建mysite测试站点:django-admin.py startproject mysite
2、创建测试页:hello.py,内容如下:
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello, Django!')
3、创建mod_py_dj.conf配置文件,内容如下:
- LoadModulepython_modulemodules/mod_python_so.pyd
- Listen8081
- NameVirtualHost*:8081
- <VirtualHost*:8081>
- <Location"/">
- SetHandlerpython-program
- PythonPath"['d:\\open\\www']+sys.path"
- PythonHandlerdjango.core.handlers.modpython
- SetEnvDJANGO_SETTINGS_MODULEmysite.settings
- PythonAutoReloadOff
- PythonDebugOn
- </Location>
- </VirtualHost>
注:此VirtualHost中,不用配置DocumentRoot,否则额外添加如下:
- <Directory"d:\\open\\www">
- OptionsFollowSymLinks
- AllowOverrideAll
- Orderallow,deny
- Allowfromall
- </Directory>
不配置DocumentRoot,少些配置。
4、修改url.py文件,添加一行:
(r'^hello/$', 'mysite.hello.index')
5、测试,http://localhost:8081/hello/