首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

windows下安装apache + python + django + mod_wsgi.so解决思路

2012-03-29 
windows下安装apache + python + django + mod_wsgi.so对应版本:Apache:Apache HTTP Server (httpd) 2.2.1

windows下安装apache + python + django + mod_wsgi.so
对应版本:
Apache:Apache HTTP Server (httpd) 2.2.19
Python:Python2.7
Django:Django-1.3
Mod_wsgi.so:mod_wsgi-win32-ap22py27-3.3.so
1、下载相应Python和Apache版本的mod_wsgi.so,比如:
mod_wsgi-win32-ap22py27-3.3.so – Apache 2.2 / Python 2.7
2、下载只有一个文件:mod_wsgi.so,如果文件不是该文件名,请修改文件名。将该文件拷贝到Apache的modules目录
3、Apache的httpd.conf文件中最后加入以下两行:
LoadModule wsgi_module modules/mod_wsgi.so
Include “C:/Python27/code/gp/apache/apache_django_wsgi.conf”
第一行是让apache加载mod_wsgi模块
第二行是让apache加载web应用程序的配置文件,其中apache_django_wsgi.conf这个文件可也可以在httpd.conf文件里面,这样提取出来有利于维护。
4、创建django程序,比如我上面的gp程序放置在“C:/Python27/code/”里面。
5、在gp目录下创建一个apache文件夹,里面有两个文件:apache_django_wsgi.conf和django.wsgi。
apache_django_wsgi.conf文件内容:
# 设置django admin静态资源的访问路径
Alias /static/ “C:/Python27/code/gp/static/”
<Directory “C:/Python27/code/gp/static”>
Allow from all
</Directory>
# 设置root,不要使用”^/”
WSGIScriptAlias / “C:/Python27/code/gp/apache/django.wsgi”
<Directory “C:/Python27/code/gp/apache”>
Allow from all
</Directory>

django.wsgi内容:
import os
import sys

#Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)

os.environ['DJANGO_SETTINGS_MODULE'] = ‘gp.settings‘
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

启动Apache即可。



[解决办法]
书写比较乱,排版糟糕,半角全角引号混用,质量不高。
共享的意图是很好的,但要是不细心文档化,还不如不共享。

热点排行