---
title: "开始学习python，配置web环境并部署django"
author: "Mirima"
date: "2009-03-16T23:43:02Z"
tags: []
slug: "python-web-django"
draft: false
lastmod: "2009-03-17T00:06:22Z"
id: 350090
url: "https://mirima.iteye.com/blog/350090"
---

在vista下配置
1.下好并安装apache_2.2.11-win32-x86-openssl-0.9.8i.msi
2.下好 python3后发现没有匹配的Mod_python，在http://apache.mirror.phpchina.com/httpd/modpython/win/最新的Mod_python还是2007年2月的，仅支持python2.5。
  重新下好python2.5，并设置好system path
3.安装Mod_python
4.根据http://www.modpython.org/live/current/doc-html/modpython.html的例子做测试
  在apache 的 httpd.conf中设置
  LoadModule python_module modules/mod_python.so
  <Directory "D:/Apache Software Foundation/Apache2.2/htdocs/test"> 
        AddHandler mod_python .py
        PythonHandler mptest 
        PythonDebug On 
  </Directory>
  在/htdocs/下建立test目录，并建立mptest.py文件，编辑内容
  from mod_python import apache
  def handler(req):
	req.content_type = 'text/plain'
	req.write("Hello World!")
        return apache.OK
  启动apache，http://localhost:8080/test/mptest.py,出现Hello World!，测试ok
5.安装Django，下载Django-1.0.2-final，解压后cmd到其目录执行python setup.py install， 会将django安装到python2.5目录中
6.建立一个目录 testDjango，将\Python25\Scripts下的django-admin.py copy过去，并执行python django-admin.py startproject myproject，会在testDjango下生存myproject目录和4个py文件
7.测试django，在httpd.conf中加入
   <Location "/myproject">
	SetHandler python-program
	PythonPath " + sys.path"
	PythonHandler django.core.handlers.modpython
	SetEnv DJANGO_SETTINGS_MODULE myproject.settings
	PythonDebug On
   </Location>
   重启apache，键入http://xxx:8080/myproject，出现django提示页面，ok