1、 Djangosettings的路径问题

要将相对路径改为绝对路径。主要有: MEDIA_ROOTTEMPLATE_DIRSSTATIC_PATH

示例:

MEDIA_ROOT = 'D:/WorkDev/workspace/djangoTest'

TEMPLATE_DIRS = (

    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".

    # Always use forward slashes, even on Windows.

    # Don't forget to use absolute paths, not relative paths.

    'D:/WorkDev/workspace/djangoTest/templates',

)

STATIC_PATH = 'D:/WorkDev/workspace/djangoTest/media'

2、 httpd.conf中应加入mod_pythonmodule

http.conf中必须加入:

LoadModule python_module modules/mod_python.so

3、 VirtualHost的配置

取消httpd.confInclude conf/extra/httpd-vhosts.conf前的注释,就可以在httpd-vhosts.conf文件中配置VirtualHost

4、 PythonPath的路径问题

   <Location "/">

        SetHandler python-program

        PythonPath "['D:/WorkDev/workspace'] + sys.path"

        PythonHandler django.core.handlers.modpython

        SetEnv DJANGO_SETTINGS_MODULE djangoTest.settings_apache

        PythonAutoReload Off

        PythonDebug On

</Location>

注意这里的PythonPath,将project的目录加入PythonPath时,应为此project的上一级目录,比如这里就不能写为‘D:/WorkDev/workspace/ djangoTest’,否则会找不到settings的配置。

5、 静态文件的配置

为了让图片、cssjs能够被apache加载,需进行如下配置:

Alias /site_media D:/WorkDev/workspace/djangoTest/media

<Location "/site_media">

    SetHandler None

</Location>

6、 静态文件无法加载的问题

首先,检查Alias设置的路径是否正确;

其次,检查settings.py中的MEDIA_ROOTTEMPLATE_DIRSSTATIC_PATH是否设置为绝对路径;

最后,检查apacheerror日志,若发现:

[Thu Jul 31 14:36:08 2008] [error] [client 127.0.0.1] client denied by server configuration: D:/WorkDev/workspace/djangoTest/media/djangopowered.gif, referer: http://localhost:8080/address/

那么说明是因为对这些静态文件的访问被拒绝了,应加入Directory的配置:

<Directory "D:/WorkDev/workspace/djangoTest/media/">

        Order Deny,Allow

        Allow from all

</Directory>

重启apache服务。

以上均为我在搭建apache+mod_python时遇到的问题,希望能给遇到同样问题的朋友一点帮助。