查看文章 |
在XAMPP中增加Python/Django/MySQLdb的支持(Windows篇)
2010/01/05 17:34
之前写过一篇。这里优化配置后重新总结下。方便自己查看。 首先准备工作。所需软件 |
| mod_wsgi-win32-ap22py26-3.0.so |
2) 配置http.conf
修改 /xampp/apache/conf/httpd.conf 在最后增加一行
# Python settings
Include "conf/extra/python.conf "
3) 配置python.conf
创建 /xampp/apache/conf/extra/python.conf 文件,内容如下:(有待继续优化!)
--------------------------------------------------------------------
LoadModule wsgi_module modules/mod_wsgi.so
<IfModule mime_module>
AddType text/html .py
</IfModule>
<VirtualHost *:80>
AliasMatch /(media/.*\.(css|gif|jpg|png|js|)) C:/Python26/Lib/site-packages/django/contrib/admin/$1
WSGIScriptAlias /python/xeye/ "D:/xampp/htdocs/python/x3y3/conf/xeye.wsgi"
<Directory "D:/xampp/htdocs/python/xeye">
Order allow,deny
Allow from all
</Directory>
<Directory "D:/xampp/htdocs/python/xeye/static">
Order Deny,Allow
Allow from all
</Directory>
<Directory "D:/xampp/htdocs/python/xeye/conf">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
---------------------------------------------------------------------
static 文件夹是用来存放静态文件的,比如 css,js,PNG,jpg,gif,zip 等等,本地测试用,所以配置的可以列出目录
4) 创建Django Project
eg: 在CMD中 cmd >python django-admin.py startproject xeye
在 django 新创建的project x3y3 目录中创建conf 目录 ,写入 xeye.wsgi 文件,内容如下:
----------------------------------------------------------------------
import os
import sys
# redirect sys.stdout to sys.stderr for bad libraries like geopy that uses
# print statements for optional import exceptions.
sys.stdout = sys.stderr
from os.path import abspath, dirname, join
from site import addsitedir
from django.core.handlers.wsgi import WSGIHandler
sys.path.insert(0, abspath(join(dirname(__file__), "../")))
sys.path.insert(0, abspath(join(dirname(__file__), "../../")))
os.environ["DJANGO_SETTINGS_MODULE"] = "xeye.settings" #Your settings module name
application = WSGIHandler()
---------------------------------------------------------------------
访问用Django创建的poject http://127.0.0.1/python/xeye 就可以看到

Done, 这样Django + MySQL 的本地开发环境就搭建完成了。
同时,由于使用的是XAMPP,所以还支持 PHP/Perl/Pear/Asp/CGI 的开发环境。
最后修改的XAMPP加载的模块如下:
Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_wsgi/3.0 Python/2.6.4 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 Server at localhost Port 80
这里还有一份我修改好的 Python for Xampp 的修改文件。 可以在XAMPP 的控制面板看到状态 :)

最近读者:




