Home » Django » why my django admin site does not have the css style

why my django admin site does not have the css style

Posted by: admin November 30, 2017 Leave a comment


i make a django admin site using django development version

but it does not have a css style :

alt text

what can i do .



Django does not serve static files on it’s own. You have to tell it where the files are.

The ADMIN_MEDIA_PREFIX in the settings.py will point Django in the right location.

Since you’re using the development version, you’ll want the dev-specific document for static files how-to. Adam’s link will lead you to the 1.2 version.


After setting up your STATIC_ROOT and STATIC_URL, you may have to run

python manage.py collectstatic


ADMIN_MEDIA_PREFIX is deprecated now, use STATIC_URL instead. Setting STATIC_URL = '/static/' in settings.py should do the job. Try:

import os.path  import sys

PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))

and then:

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

Works on Django 1.4 pre-alpha SVN-16920.


I ran into this issue as well following the Django Book Tutorial.
In Chapter 5|Installing the model, the book states when referring to the default INSTALLED_APPS-
“Temporarily comment out all six of those strings by putting a hash character (#) in front of them.”

Then, in Chapter 6, the Book tells the reader to uncomment 4 of those 6 lines-
“note that we commented out these four INSTALLED_APPS entries in Chapter 5. Uncomment them now.”

But the statcifiles line is what is needed to restore CSS to the admin page, so uncomment that


I read several other threads trying to fix this…resorted to an alias as in other threads.
This assumes that your own custom app is serving static files correctly, which would indicate that your STATIC_ROOT and STATIC_URL have proper settings.

STATIC_URL = '/static/'

Then (from your static directory):

[email protected]:/srv/www/mysite.com/app_folder/static$ sudo ln -s /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/ admin

Hope this helps someone…there are a lot of threads on this topic.


In /project_name/project_name/settings.py you need to set STATIC_URL to tell your site what url to use for static files.

Then set STATIC_ROOT to be some folder on your filesystem that is not the same as any of your directories listed in STATICFILES_DIRS list.

Once STATICFILES_ROOT is set, you would run python manage.py collectstatic from the project directory.

This will copy all the admin static files and all files in any other folders listed in the STATICFILES_DIRS list. Basically this puts all your static files in one place so you you can move them to your CDN when deploying your site. If you are like me and don’t have a CDN, then you have two options:

  1. Add the folder you set as STATIC_ROOT to the STATICFILES_DIRS list. This will allow the staticfiles finders in django to locate all the static files.
  2. Move the entire folder of static files somewhere else on your file system and direct STATICFILES_DIRS to include that new location.

I make no comments about security with this answer, it is just the way I have been able to develop with my web server for small projects. I expect that you will want a CDN as django suggest if you are doing anything larger scale.

I just ran into this issue and this method didn’t quite do what I think you want. What ended up working for me was after I ran collectstatic I just copied the admin static files that it put into STATICFILES_ROOT into the directory that I had used for my own static files. That solved the issue for me.


If you are using Apache server to host your django site, you need to make sure the static alias point to your /directory to site/site_media/static/. If your static files are in /directory to site/site/site_media/static/, the previous Apache alias configuration will not work.


Ensure that 'django.contrib.staticfiles' is in your INSTALLED_APPS in your settings.py


In addition to many of the other answers being useful, I had a problem that hasn’t yet been noted. After upgrading from Django 1.3 to 1.6, my static files directory had a broken symbolic link to the django admin static files.

My settings.py was configured with:


According to this answer,

Django will now expect to find the admin static files under the URL

I had a symbolic link /var/www/static/my-dev/admin which was set to:

admin -> /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/

That location no longer exists in django 1.6, so I updated the link to:

admin -> /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/

And now my admin site is working properly.


While following the Django tutorial, I had a similar problem and in my case the issue was the mimetype used by the development server when serving css files.

The mimetype served was ‘application/x-css’ which led to following warning message in Chrome (in the ‘Network’ tab of the Developer tools):

Resource interpreted as Stylesheet but transferred with MIME type
application/x-css: “

The workaround that I’ve found: changing the mimetype to be served by adding following lines to the django webapp’s manage.py file:

import mimetypes
mimetypes.types_map['.css'] = 'text/css'

Note: worked for me with Django 1.7.4 on Python 2.7 and Chrome 40.0


Same sort of issue i encountered while developing a site in django-1.10.5 and python-2.7.13. But in my firefox-51 and chrome, the login page was able to get the css but still there was no styling. But weirdly it was working on IE-8..

I tried do every possible thing mentioned here and suitable to my set of sw versions. None worked.

But when i tried the same site on other system which had the python-2.7.8, it worked..

Just posted if it may help someone…

edited: later I found that in python-2.7.13, writing the following two lines in settings.py (plus clearing the cache of the browser) had done the trick

import mimetypes
mimetypes.add_type("text/css", ".css", True)


If you have a value set in settings.py for STATICFILES_DIRS and the declared folder doesn’t exist or in wrong location it will cause the Admin to have no styling
by defining
STATICFILES_DIRS = ( os.path.join(BASE_DIR,”static”))
and the static folder doesn’t exist