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也要是絕對路徑

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值