---
title: "Django之Apache/mod_python安装及HelloWorld"
author: "fudehai001"
date: "2009-11-12T11:31:03Z"
tags: []
slug: "django-apache-mod-python-helloworld"
draft: false
lastmod: "2009-11-12T11:31:03Z"
id: 515174
url: "https://laozy.iteye.com/blog/515174"
---

from: http://hideto.iteye.com/blog/42538 Django自带的服务器不是很好，改成Apache+mod\_python的方式写一个HelloWorld 一、安装Apache 下载地址： http://httpd.apache.org/ apache\_2.2.3-win32-x86-no\_ssl.msi安装很方便，注意安装过程中要填email，否则启动报错 二、安装mod\_python 下载地址：http://www.modpython.org/ mod\_python-3.3.0b.win32-py2.4-Apache2.2.exe点击安装即可，注意python用的是2.4的 三、配置虚拟主机 编辑httpd.conf： 设置MaxRequestsPerChild 1，这样可以在开发阶段不用重启Apache进行测试 添加LoadModule python\_module modules/mod\_python.so 去掉注释Include conf/extra/httpd-vhosts.conf 假如工作目录为D:\\py,cmd切换到该目录运行“django-admin.py startproject myproj” 编辑httpd－vhosts.conf： NameVirtualHost 127.0.0.1:80 &lt;virtualhost&gt;&lt;location&gt; SetHandler python-program PythonPath "\['D:/py'] + sys.path" PythonHandler django.core.handlers.modpython SetEnv DJANGO\_SETTINGS\_MODULE myproj.settings PythonAutoReload Off PythonDebug On &lt;/location&gt;&lt;/virtualhost&gt; 在D:\\py\\myproj下新建helloworld.py： from django.http import HttpResponse def index(request): return HttpResponse('Hello, Django!') 修改urls.py： from django.conf.urls.defaults import * urlpatterns = patterns('', # Example: # (r'^myproj/', include('myproj.apps.foo.urls.foo')), (r'^$', 'myproj.helloworld.index'), # Uncomment this for admin: # (r'^admin/', include('django.contrib.admin.urls')), ) OK，启动Apache访问http://localhost吧