问题
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