1

Folks, the default CSS of my Django admin section is not loading (setup uses nginx reverse proxy + gunicorn, OS is the Debian-based Ubuntu).

The following is part of etc/nginx/sites-available/myproject:

location /static/admin {

        alias /home/mhb11/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/contrib/admin/static/;
    }

That, btw, points to the correct location of django admin's css files, and is written below location /static/ {} snippet (not shown here).

Note that I have tried the root directive instead of alias too, to no avail. Also note that this error pertains solely to django admin static files. The project related static files are working perfectly. Also note that my settings.py file includes 'django.contrib.staticfiles', in INSTALLED_APPS and STATIC_URL = '/static/'.

What am I missing? Please ask for more information in case it is needed.

4
  • You should have defined a static_dir and run collectstatic. Commented Jan 16, 2016 at 20:22
  • Hey Daniel. I have STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) in settings.py, if that's what you're implying. So you mean to say I should run python manage.py collectstatic? Commented Jan 16, 2016 at 20:35
  • Yes, that he meant, but for the command you have to specify the static_root (must be different unlike staticfiles_dirs, most common place is e.g. /var/www/your_domain/static/). Commented Jan 16, 2016 at 20:59
  • In settings.py I have STATIC_ROOT = 'staticfiles'. Commented Jan 16, 2016 at 22:55

1 Answer 1

1

It may not be significant, but for consistency, your location path and alias path should both end with a / or neither end with a /.

With your current configuration, the server is constructing path names with an embedded //, like /home/mhb11/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/contrib/admin/static//somefile.css.

Try:

location /static/admin/ {
    alias /home/mhb11/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/contrib/admin/static/;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Richard. Let me get back to you on whether this alleviated my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.