Django Admin Page Missing CSS

Django Admin Page missing CSS

In addition to correcting the symbolic link as Daniel Roseman suggested, you'll need to make sure that the user that is running Apache has read access to the admin media.

  • If you do ls -l in your media directory, do you see the symbolic link?
  • If you cd admin from your media directory, does it work? If you then run ls can you see the admin media?
  • Does the user that runs Apache have read access to the admin media?

If all those things work, then please update your question with your current configuration and results of those commands and we'll take another look.

Response to Update: Ok, the permissions look ok. It looks like you've got the directory structure in your media directory a little bit wrong.

The fact that /usr/lib/python2.6/site-packages/django/contrib/admin/media/ was empty is disturbing, too. Once you solve the immediate problem you may want to look into reinstall django in the expected place.

Anyways, here's how the structure should look:

$ cd media
$ ls -la
drwxr-xr-x 2 root root 4096 Apr 13 03:33 .
drwxr-xr-x 3 root root 4096 Apr 8 09:02 ..
lrwxrwxrwx 1 root root 60 Apr 13 03:33 admin -> /usr/lib/python2.6/site-packages/django/contrib/admin/media/
-rw-r--r-- 1 root root 9 Apr 8 09:02 test.txt

That is, inside of the media/ directory their should be a link called admin directly to the /admin/media directory of your django installation.

To fix what you've got, inside of the media/admin/ directory run:

rm media
cd ..
rmdir admin

and then re-create the symlink as suggested in Daniel Roseman's answer.

Django admin interface missing css styling in production

Could you please try below steps and let me know if it's working or not?

Apply below changes in settings.py file:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Remove below line from your settings.py:

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]

Execute below command in production:

python manage.py collectstatic

Update nginx file like below one:

server {
listen 80;
server_name MY_SERVER_IP;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
autoindex on;
autoindex_exact_size off;
root /home/MYUSERNAME/myproject;
}

location /media/ {
autoindex on;
autoindex_exact_size off;
root /home/MYUSERNAME/myproject;
}
}

Explanations:

  • STATIC_ROOT is the folder where static files will be stored after
    using python manage.py collectstatic
  • STATICFILES_DIRS is the list of folders where django will search for additional static files aside from the static folder of each app installed.

In this case our concern was Admin related CSS files that why we use STATIC_ROOT instead of STATICFILES_DIRS

Django Admin CSS missing

Django recommends that you deploy static files with a web server other than wsgi.

  1. In settings.py, set:

STATIC_ROOT = 'static'


  1. Run python manage.py collectstatic, which will copy the Django admin static files to /path/to/project/static/

  2. Configure your static file server. If you use Nginx, you could add this config:

    location /static/ {                              
    alias /path/to/project/static/;
    expires modified +1w;
    }
  3. Reload your web server

You should now have access to the static files.

Django Admin Page missing CSS in IIS

I was able to find an answer with the help of a colleague.

The answer is highlighted here: Link

If you follow the above solution, please keep in mind the following (which is what the above person mentioned):

  • The Static folder where you keep all the CSS, jpegs, etc files is not the same as the static folder they are referring to in the solution
  • Make sure you run the command collectstatic to compile all the static files from the STATIC_URL folder to the STATIC_ROOT folder
  • When you run the collectstatic it will compile the Admin static files as well

cPanel: Django Admin Portal not loading Static/CSS files

You can install whitenoise

pip install whitenoise

Django admin CSS missing, after collecting static, with python manage.py runserver

You need to enable DEBUG and enable staticfiles app. If you do not want to enable DEBUG, you may run runserver with --insecure commandline parameter.

https://docs.djangoproject.com/en/1.9/ref/contrib/staticfiles/

Django staic and admin static css files loaded but not applied to page

It seems that your machine has configuration problem from the roots like when you had first installed python or some other ide, pip, django etc.
Try uninstalling everything and install again and even if this doesn't help reset your pc.
This ain't a coding problem seems like something wrong in configuration of python, pip or django from the roots.



Related Topics



Leave a reply



Submit