How to use Django with Apache and mod_python

os: ubuntu 10.04

django: version 2.5

apache: 2

python: 2.6

1. install python, django, apache, mod_python

apt-get install

2.edit httpd.conf

<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">  
    AllowOverride None  
    Options None  
    Order allow,deny  
    Allow from all  
</Directory>  
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Location "/mysite">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonInterpreter mysite
    PythonDebug On
    PythonPath "['C:/Python/Django/apps'] + sys.path"
</Location>


Location "/mysite" 而不要是Location "/mysite/"

设置MaxRequestsPerChild 1,这样可以在开发阶段不用重启Apache进行测试

Alias /media/是django admin 管理界面要用到的

另一種方法

cd /var/www

sudo ln -s  ~/media media

sudo ln -s ~/django_src/django/contrib/admin/media admin_media


# Absolute path to the directory that holds media.

# Example: "/home/media/media.lawrence.com/"

MEDIA_ROOT = '/home/YOUR_USERNAME/media/'# URL that handles the media served from MEDIA_ROOT. Make sure to use a

# trailing slash if there is a path component (optional in other cases).

# Examples: "http://media.lawrence.com", "http://example.com/media/"

MEDIA_URL = 'http://yourdomain.com/media/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a

# trailing slash.

# Examples: "http://foo.com/media/", "/media/".

ADMIN_MEDIA_PREFIX = '/admin_media/'


所用到的路徑為絕對路徑

若數據庫類開為sqllite3, databasename也要是絕對路徑

你可能感兴趣的:(How to use Django with Apache and mod_python)