windows+apache+mod_python配置django运行环境
时间:2021-02-01 04:06:54
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配置文件,内容如下:
LoadModule python_module modules/mod_python_so.pyd
Listen 8081
NameVirtualHost *:8081
<VirtualHost *:8081>
<Location "/">
SetHandler python-program
PythonPath "['d:\open\www'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonAutoReload Off
PythonDebug On
</Location>
</VirtualHost>
注:此VirtualHost中,不用配置DocumentRoot,否则额外添加如下:
<Directory "d:\open\www">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
不配置DocumentRoot,少些配置。
4、修改url.py文件,添加一行:
(r'^hello/$', 'mysite.hello.index')
5、测试,http://localhost:8081/hello/