Django style sheets for the Admin embedded site do not load on my production server, which runs Django 1.6. I see that many other people have encountered this problem, and I tried all the solutions that were provided to them, but no one works. My Django site runs on top of Gunicorn 19.1.1 behind the Nginx v proxy. 1.2.1.
Since I am going to create a dashboard and will use the admin site much more than manage my users, groups and models, I created the "admin" application on my site:
INSTALLED_APPS += ('apps.admin', )
I override and extend some of the Django admin templates and copied them from django.contrib.admin.templates here:
/www/site/apps/admin/__init__.py
/www/site/apps/admin/models.py
/www/site/apps/admin/views.py
/www/site/apps/admin/urls.py
/www/example/apps/admin/templates/admin/base.html
/www/example/apps/admin/templates/admin/base_site.html
/www/example/apps/admin/templates/admin/index.html
/www/example/apps/admin/templates/admin/my_dashboard.html # mine
Here are the local settings from my urls.py file
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/dashboard/$',
'apps.admin.views.dashboard',
{'template': 'my_dashboard.html'},
name='dashboard'),
)
. :
/www/example/static/css
/www/example/static/js
. Django , , .
STATIC_ROOT = "/var/www/example/static/"
URL:
STATIC_URL = '/static/'
:
STATICFILES_DIRS = (
'/www/example/static'
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
Nginx:
upstream gunicorn {
server 127.0.0.1:8000 fail_timeout=0;
}
server {
listen 80;
server_name www.example.com;
rewrite ^/(.*) http://example.com/$1 permanent;
}
server {
listen 80;
server_name example.com;
root /www/example;
client_max_body_size 4G;
keepalive_timeout 5;
location /static/ {
alias /www/example/static/;
}
location /media/ {
alias /var/www/example/media/;
}
try_files $uri @django;
location @django {
proxy_pass http://gunicorn;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /www/example/static;
}
}
, . , :
http://example.com/static/img/small_img.jpg
Nginx 404, Django...
http:
... , View Source :
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="/static/admin/css/login.css" />
:
- , "django.contrib.staticfiles" "django.contrib.admin" INSTALLED_APPS.
- Python STATIC_ROOT, STATIC_URL STATICFILES_DIR.
- "collectstatic" , Django STATIC_ROOT.
- nginx, , Nginx.
- /www/example/static/admin, "" , .../django/contrib/admin/static/ .
- Chrome , , - , 404 .
"" , Django hrefs base.html. .
. - , ? , . , . !