一、下載httpd-2.2.16-win32-x86-no_ssl.msi 安裝
注意如果開啟了iis記得停止
二、下載mod_wsgi-win32-ap22py26-3.3.so
:http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-win32-ap22py26-3.3.so
三、修改mod_wsgi-win32-ap22py26-3.3.so 為mod_wsgi.so 並拷貝到C:/Program Files/Apache Software Foundation/Apache2.2/modules (具體目錄就是你安裝apache的目錄)
四、修改httpd.conf(一般在c:/Program Files/Apache Software Foundation/Apache2.2/conf)添加如下內容:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / "D:/Django/django/bin/blogmysite/django.wsgi"
<Directory "D:/Django/django/bin/blogmysite">
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
說明:我的django安裝在d:/django/django下
建立的proejct 叫blogmysite
建立的app叫blog
五、在工程目錄下建立wsgi檔案(我的是:D:/Django/django/bin/blogmysite/),內容:
import os
import sys
import django.core.handlers.wsgi
sys.path.append('D:/Django/django/bin')
sys.path.append('D:/Django/django/bin/blogmysite')
sys.path.append('D:/Django/django/bin/blogmysite/blog')
os.environ['DJANGO_SETTINGS_MODULE'] = 'blogmysite.settings'
application = django.core.handlers.wsgi.WSGIHandler()
六、瀏覽,打入http://localhost/blog 顯示正常
如果出錯可以查看c:/Program Files/Apache Software Foundation/Apache2.2/logs/error.log
如果出現如下錯誤:
ImportError: No module named XXX.models
或者
[Tue Aug 17 23:11:22 2010] [error] [client 127.0.0.1] ImportError: Could not import settings 'XXX.settings' (Is it on sys.path? Does it have syntax errors?): No module named XXX.settings
你可以在django.wsgi 裡面加入相關的程式目錄(sys.path.append('你的目錄'),注意不要用/結尾)