Django Admin not working / ugly - works with nginx and gunicorn

I have nginx, gunicorn, django running on an instance of Ubuntu EC2. The whole site is working fine. With the exception of the administrator. Admin is not displayed correctly. I ran "python manage.py collectstatic" and edited STATIC_ROOT and STATIC_URL. When I load the admin page, this is ugly, but when I check the source, the CSS files are located, they should be

<title>Site administration | Django site admin</title> 
<link rel="stylesheet" type="text/css" href="http://staticfiles.mydomain.com/static/admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="http://staticfiles.mydomain.com/static/admin/css/dashboard.css" />

I can look at nginx access.log and see how the files are requested and delivered, but the page does not display correctly. This is similar to the fact that files are accepted but not processed. The error log is blank.

solvable

On the console tab in the Chrome Developer Tools, I noticed the following:

Resource interpreted as Script but transferred with MIME type text/plain: "http://staticfiles.<mydomain>.com/static/admin/js/jquery.min.js". 

, , , . , nginx.conf ...

location /static/admin/js/ {
  default_type text/javascript;
  alias /home/ubuntu/webapps/<myproject>/static/admin/js/;
}

location /static/admin/css/ {
  default_type text/css;
  alias /home/ubuntu/webapps/<myproject>/static/admin/css/;  
}

; django javascript . , - .

+4
2

;

1.step

settings.py edit

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
STATIC_ROOT = "/opt/venv/myDjangoProject/static/"
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)

2.step

collesctstatic :)

python manage.py collectstatic
+1

- include /etc/nginx/mime.types; http nginx.

0

All Articles