1. 用Apache和mod_python来部署Django
(1)安装mod_python
http://www.modpython.org/
(2)加载mod_python
1
|
LoadModule python_module modules/mod_python.so
|
(3)设置配置文件
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Listen
8001
NameVirtualHost localhost: 8001 < virtualhost localhost: 8001> DocumentRoot H:\Python_Work SetHandler python-program PythonHandler django.core.handlers.modpython PythonPath "['H:\Python_Work\Django','H:\Python_Work'] + sys.path" < location "/mysite/"> SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonInterpreter mysite PythonDebug On </ location> < location "/media/"> SetHandler None </ location> </ virtualhost> |
(4)修改url规则(mysite_urls.py)
1
2 3 4 5 6 7 8 9 |
from django.
conf.
urls.
defaults
import *
from django. contrib import admin from django. views. generic. simple import direct_to_template from django. views. generic import list_detail from mysite. books. models import * urlpatterns = patterns ( '' , (r '^mysite/' , include ( 'mysite.urls' ) ) , ) |
(5)部署静态文件 将H:\Python_Work\Django\django\contrib\admin下的media文件夹拷到H:\Python_Work下 (6)注意事项 每次修改项目配置文件都要重启Apache以重新加载,设置MaxRequestsPerChild 1,这样可以在开发阶段不用重启Apache进行测试,不过对服务器性能有影响