我的Django项目:viewPractice
①:下载modwsgi,将解压后的mod_wsgi.so放到apache的modules下
②:在apache的conf下的httpd.conf中加入下面语句:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / "D:/django_worksapce/viewPractice/viewPractice/django.wsgi"
注意:这里的路径要用UNIX风格的,即权为'/'
③:在你的django项目中settings.py所在目录下建立django.wsgi文件,这其实是一个python文件,内容如下:
<span style="font-size:18px;">import os
import sys
import django.core.handlers.wsgi
sys.path.append(r'D:\django_worksapce\viewPractice')#这里面是此文件所在文件夹的父文件夹 #位置
os.environ['DJANGO_SETTINGS_MODULE'] = 'viewPractice.settings'#这里是改成你的setting即可
application = django.core.handlers.wsgi.WSGIHandler()</span>
④:在回到httpd.conf,找到这一代码块的位置,做修改如下加入,即将默认的APache的DocumentRoot改成你的项目所在的位置:
<span style="font-size:18px;">#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "D:\django_worksapce\viewPractice">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
# Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
# AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory></span>
注意:.每改一次httpd.conf,重启apache才会有效。