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
<virtualhost><location>
SetHandler python-program
PythonPath "['D:/py'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproj.settings
PythonAutoReload Off
PythonDebug On
</location></virtualhost>
在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吧
Django之Apache/mod_python安装及HelloWorld
最新推荐文章于 2025-07-03 13:48:04 发布
本文介绍如何使用Apache和mod_python部署Django应用,包括安装Apache、安装mod_python及配置虚拟主机等步骤,并通过一个简单的Hello World示例展示整个部署过程。
1616

被折叠的 条评论
为什么被折叠?



