Apache not serving django admin static files

前端 未结 4 1164
情歌与酒
情歌与酒 2020-12-02 09:18

Let me thanks you guys at the Stack Overflow community for helping me with various Django and Apache (with mod_wsgi) errors. I\'ve asked about 5 related questions so far and

相关标签:
4条回答
  • 2020-12-02 09:36

    The following did the trick for me. (Django 1.11 with Python 3.6)

    Alias /static/admin /usr/local/lib/python3.6/site-packages/django/contrib/admin/static/admin
    <Directory "/usr/local/lib/python3.6/site-packages/django/contrib/admin/static/admin">
        Require all granted
        Order allow,deny
        Allow from all
       # AllowOverride All
    </Directory>
    
    Alias /static /var/www/app/static
    

    Hope it helps.

    0 讨论(0)
  • 2020-12-02 09:40

    I think you should change:

    Alias /media/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media"
    

    to:

    Alias /static/admin/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media"
    

    Because you have:

    ADMIN_MEDIA_PREFIX = '/static/admin/'
    
    0 讨论(0)
  • 2020-12-02 09:52

    I got solution, I looked at the access_log files inside /var/log/httpd/

    127.0.0.1 - - [28/Dec/2013:14:49:20 -0500] "GET /static/admin/css/login.css HTTP/1.1" 200 836 "http://127.0.0.1/admin/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 CentOS/3.6.24-3.el6.centos Firefox/3.6.24"
    

    so I added following tags in /etc/httpd/conf/httpd.conf file,

    Alias /static /usr/lib/python2.6/site-packages/django/contrib/admin/static
    

    inside <VirtualHost 127.0.0.1:80> tag

    then I restarted service using

    service httpd restart
    

    and it Works!!!

    0 讨论(0)
  • 2020-12-02 09:57

    That's because you haven't setup your STATIC files...

    Add to settings:

    STATIC_URL = '/static/'
    STATIC_ROOT = '/var/www/static/'
    

    Then run "python manage.py collectstatic"

    That will put all the files under STATIC_ROOT which STATIC_URL will serve... You shouldn't point Apache at your Python lib files!!

    If you want your own app-specific static files as well, setup "STATICFILES_DIRS".

    0 讨论(0)
提交回复
热议问题