[Django]-Django Admin CSS missing

40๐Ÿ‘

โœ…

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.

๐Ÿ‘คjingping.yi

28๐Ÿ‘

In Django 1.4 ADMIN_MEDIA_PREFIX is deprecated. Here are the steps I followed to catch up with these somewhat recent Django changes:

  1. in settings.py, add django.contrib.staticfiles to INSTALLED_APPS

  2. in settings.py define STATIC_URL โ€” the staticfiles app wonโ€™t run without it. While using runserver theyโ€™ll get handled magically, but when you deploy, this needs to be a location where those resources can be fetched by a browser.

I think thatโ€™s all there was to it.

๐Ÿ‘คJoe Germuska

19๐Ÿ‘

Iโ€™m using Django 1.4.3

What did NOT work for me:
No matter how much I edited ADMIN_MEDIA_PREFIX in settings.py I noticed no change in the HTML generated for the Django Admin pages. It always says /media/admin/base.css when I view the source.

What DID work for me.
Copied the โ€˜adminโ€™ folder from /django/contrib/admin/static/ and pasted it into my projects โ€˜mediaโ€™ folder

Now it works great.

๐Ÿ‘คnu everest

13๐Ÿ‘

It seems dumb, but I actually had this exact issue and the solution was to set DEBUG=False to DEBUG=True on my local dev environment. When debug is set to False, it thinks itโ€™s in a production environment which relies on a place to put static files, such as /var/www/html/static, whereas the debug set to True just uses the local directory.

๐Ÿ‘คBlairg23

5๐Ÿ‘

Also make sure that AppDirectoriesFinder is not commented, happens when youโ€™re trying to customize your own app structure. Unfortunatelly itโ€™s pointless to seek such information in official docs.

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
๐Ÿ‘คbios

3๐Ÿ‘

just change one thing in settings.py

DEBUG = False # not working if you are not serve your static files for production.

just change

DEBUG = True 
๐Ÿ‘คUmer Aziz

2๐Ÿ‘

You need a trailing slash in your ADMIN_MEDIA_PREFIX setting.

Change to:

ADMIN_MEDIA_PREFIX = '/static/admin/' 

1๐Ÿ‘

in my project, the solution is in settings.py, set:

DEBUG = False # debug false mod not working css

๐Ÿ‘คxingpei Pang

0๐Ÿ‘

Iโ€™m using chef to auto-build my django server on an AWS Ubuntu server. This post helped, but what I wound up doing was to add the directory to the package admin static pages in a local_setings.py:
https://github.com/jaycrossler/geoq-chef-repo/blob/master/cookbooks/geoq/templates/default/local_settings.py.erb#L16

(added to local_settings.py or to settings.py):

STATICFILES_DIRS = ('<%= node['geoq']['virtualenv']['location'] %>/local/lib/python2.7/site-packages/django/contrib/admin/static/',)

This resulted in local_settings.py having:

STATICFILES_DIRS = ('/var/lib/geoq/local/lib/python2.7/site-packages/django/contrib/admin/static/',)

Note, that if you have other items already in your STATICFILES_DIRS, you might want to append to the list, rather than overwriting it.

๐Ÿ‘คJayCrossler

0๐Ÿ‘

One solution might be to add your local IP to the ALLOWED_HOSTS list in settings.py

e.g.

CURRENT_IP = '192.168.0.123'
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '0.0.0.0', CURRENT_IP]
๐Ÿ‘คDavid Schumann

0๐Ÿ‘

you need

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

0๐Ÿ‘

I donโ€™t know how it was resolved, but I took these steps when I encountered the same problem. I simply add these line in settings.py.

ADMIN_MEDIA_PREFIX = '/static/admin/'

STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder','compressor.finders.CompressorFinder', )

i hope this will help you all.

-3๐Ÿ‘

In settings.py
Donโ€™t use tuple for the

STATICFILES_DIRS =(
os.path.join(BASE_DIR, โ€˜staticโ€™),
)

you should use list,like this

STATICFILES_DIRS =[
os.path.join(BASE_DIR, โ€˜staticโ€™),
]

๐Ÿ‘คzijie lin

Leave a comment