唐伯虎 发表于 2021-8-12 12:38:12

windows+apache+mod_python配置django运行环境

环境: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配置文件,内容如下:



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/

文档来源:服务器之家http://www.zzvips.com/article/100965.html
页: [1]
查看完整版本: windows+apache+mod_python配置django运行环境