Django admin not serving static files on Apache

流过昼夜 提交于 2020-01-07 02:49:03

问题


I've seen similar questions but they are more than 4 years old and the answers doesn't work anymore. I have a site that works correctly on Apache, except for the admin staticfiles. The staticfiles work fine with Django's runserver. I'm kind of lost here, any advice will help.


回答1:


When you serve static files using apache, static folder is supposed to be in your /var/www/html directory. I had gone through same scenario as yours. collectstatic didnt work for me. What I did was, copied static contents of admin app to /var/www/html/static/admin. This admin directory contains four other directories css, fonts, img and js. In my case apache setup was the default so /var/www/html was my public directory. Following can be used for reference.

server
    |
    -var
       | 
        -www
            |
             -html
                  |
                  - static
                         |
                         -admin
                               |-css
                               |-fonts
                               |-img
                               |-js

You can try aforementioned approach. It would be helpful if you let know issue is resolved.




回答2:


Check the following things

1)Did you add STATIC_ROOT in settings file?

2)After activating the virtual environment(if any), did you run

python manage.py collectstatic


来源:https://stackoverflow.com/questions/40003898/django-admin-not-serving-static-files-on-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!