3

After doing the python manage.py collectstatic I found out that I can access everything in static/css but not in static/admin. To be very clear:

  1. I go to: http://mysite.com/static/admin/css/login.css and fails
  2. Manually move the folder static/admin to static/css
  3. I go to: http://mysite.com/static/css/admin/css/login.css and works!

Notice the change from /static/admin/css/ to /static/css/admin/css/ in the URLS. This means that this doesn't solve the problem because the templates continue pointing to the first URL.

I know, serving static admin files has been asked 100 times in stackoverflow but I still cannot make it work (and I am not alone for the comments I have read). It seems nobody has mention this weird problem of accessing the static/css folder and static/anyother_folder.

Some extra details:

There is no errors in the collectstatic, there is no problems with the application css's. This is what I have in my settings.py):

MEDIA_ROOT = join(PROJECT_ROOT,'../media')
MEDIA_URL = '/media/'
STATIC_ROOT = join(PROJECT_ROOT,'../static')
STATIC_URL = '/static/'

I also have tried the deprecated ADMIN_MEDIA_PREFIX without any result.

ADMIN_MEDIA_PREFIX = '/static/admin/'

My nginx configuration is simple and clear.

location /static {
    alias /home/the_home/where_the_static_is/static/;
}
location /media {
    alias /home/the_home/where_the_media_is/media/;
}

I am using the last version of Django (1.4.2).

toto_tico
  • 17,977
  • 9
  • 97
  • 116
  • This question[1](http://stackoverflow.com/questions/7241688/django-admin-css-missing) had the same problem I am having. He said he had a problem with his environment, unfortunately didn't say what :(. – toto_tico Nov 16 '12 at 15:04
  • Did you make sure that django.contrib.admin was in your installed apps? Collectstatic won't copy the files if it isn't. – Martin Larente Nov 16 '12 at 16:17
  • Thanks. django.contrib.admin is there. collectstatic is working perfectly. It places the files in static/admin, which for a non understood reason I cannot access. – toto_tico Nov 16 '12 at 16:46
  • please enable logging and post snippet of where nginx is looking when you request http://mysite.com/static/admin/css/login.css – slackjake Nov 17 '12 at 21:27
  • Thanks, I finally found what was happening. Thanks for pointing me out to the nginx again. – toto_tico Nov 19 '12 at 18:20

1 Answers1

1

Puff. So, here it was. I had another folder in nginx redirecting the /static/admin/ to the Django installation in the virtual environment. In the organization, we use a virtual machine template that pre-configure our Django projects. So, revisiting the nginx configuration I found this:

location /static/admin {
   alias /path/to/virtualenvs/my_virtualenv/path_to_the_static_admin;
}

Apparently this worked for Django 1.3 but the path changed at some point.

toto_tico
  • 17,977
  • 9
  • 97
  • 116