1. 程式人生 > >Apache部署Django專案

Apache部署Django專案

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 os
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()
5. 這就可以了,用瀏覽器開啟地址http://127.0.0.1,happy的事情就發生了!