Apache下部署Django 的样式问题

Django项目上线部署到Apache之后,登陆到后台,不出所料的话,一定会出现样式问题,主要原因是因为定位不到样式等文件,需要在httpd.conf中加入如下信息:

<VirtualHost 127.0.0.1:8888>

    <Directory /var/www/html/mysite>
          ......
    </Directory>
    <Location "/">
        SetHandler python-program
        PythonPath "['/var/www/html/mysite'] + sys.path"
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE mysite.settings
        PythonAutoReload On
        PythonOption django.root /mysite
        PythonDebug On
    </Location>

    Alias /media /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media
<Directory ...... /> #记住设定目录访问权限 <Location "/media/"> SetHandler None </Location> Alias /static /usr/local/lib/python2.6/dist-packages/django/contrib/admin/static ...... <Location "/static/"> #media和static目录不能相同 SetHandler None </Location> </VirtualHost>

 

然后修改setting.py中配置(主要修改MEDIA/STATIC/TEMPLATES几项配置):

MEDIA_ROOT = '/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/'
MEDIA_URL = '/media/'#media和static目录不能相同
STATIC_ROOT= '/usr/local/lib/python2.6/dist-packages/django/contrib/admin/static/'
TATIC_URL = '/static/' 
TEMPLATE_DIRS = ('......',)

最后重启apache。

 

 

你可能感兴趣的:(apache)