1. 保证Django项目(项目位置: E:\MyTest\Django\testProject)能正确运行,安装好Apache HTTP Server。
2. 把mod_wsgi.so放到"C:\Program Files\Apache Software Foundation\Apache2.2\modules"目录下(默认安装目录),要注意的是保证mod_wsgi.so的版本号,必须与python的版本号符合。(mod_wsgi.so下载地址:http://yun.baidu.com/share/link?shareid=3292463927&uk=3508115909,我的python版本号是2.7.2)
3. 配置Apache的配置文件httpd.conf,添加以下内容:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / "E:/MyTest/Django/testProject/django.wsgi"
<Directory "E:/MyTest/Django/testProject/">
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
4. 在项目位置(E:\MyTest\Django\testProject)下添加文件django.wsgi并编辑:
import os5. 这就可以了,用浏览器打开地址http://127.0.0.1,happy的事情就发生了!
import sys
djangopath = "C:/Python27/Lib/site-packages/django/bin"
if djangopath not in sys.path:
sys.path.append(djangopath)
projectpath = 'E:/MyTest/Django'
if projectpath not in sys.path:
sys.path.append(projectpath)
apppath = 'E:/MyTest/Django/testProject'
if apppath not in sys.path:
sys.path.append(apppath)
os.environ['DJANGO_SETTINGS_MODULE']='testProject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()