8

when i runserver the django admin is missing css.The web console says that style sheet was not loaded because its MIME type,"application/x-css", is not "text/css". This is my settings.py file

Django settings for mysite project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', 
        'NAME': 'C:/djangorevision/mysite/sqlite3.db',                       database 
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                   
        'PORT': '',                     
    }
}

ALLOWED_HOSTS = []


TIME_ZONE = 'America/Chicago'


LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True


USE_TZ = True

MEDIA_ROOT = ''

MEDIA_URL = ''


STATIC_ROOT = 'C:/djangorevision/mysite/static'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (

)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
 #    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '*4#u_xz-+7cp-x-)w(o*sr1&1$^fa409_d@7!&z%_(93u=@s=o'

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'mysite.wsgi.application'

TEMPLATE_DIRS = (
  )

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
     'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'polls'

)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,`enter code here`
        },
    }
}
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
ciira
  • 103
  • 1
  • 6

3 Answers3

7

A little late answer but this needs to be put here for completeness.

I also got this strange error on one development system (I didn't get it on other development systems for the same project). Maybe it is related to the fact that Dreamweaver (which can open css files) was installed on this system?

In any case, to resolve the issue I added the following in my settings.py:

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

This will add (and replace if already exists) the correct mimetype for css in your mimetypes list.

In case you don't want to put it in your settings.py, add it to the __init__.py file of yout settings package.

Serafeim
  • 14,962
  • 14
  • 91
  • 133
  • i included the above but i still got the error. i have dreamweaver installed in my system – ciira May 19 '14 at 12:33
  • 2
    Where did you included it ? Are youy sure that it is executed ? Try adding a print statement after ``mimetypes.add_type`` to be sure that it runs. – Serafeim May 19 '14 at 13:21
  • i included it in my settings.py, i also added the print statement and it executed. – ciira May 22 '14 at 08:29
  • Hmm... it works in my case, i really don't know what is the problem :| – Serafeim May 22 '14 at 15:13
  • the above answer solved the problem but it was great that you introduced the issue on Dreamweaver had a hand on it – ciira Jan 29 '15 at 07:13
7

I just ran into the same problem. And it seems you are right about Dreamweaver. Adding above mentioned strings into settings.py didn't helped me.

I have run search for .css at regedit and changed most suspicious registry keys/records which

  1. could be related to treating .css files as application/x-css type
  2. could be related to associating .css file extension to opening with applications, especially Dreamweaver.

It took me two iterations and I can not say for sure which one was the right shot as it might needed some time to update some cache, etc.

Though I changed it at two locations:

  1. HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.css
  2. HKEY_CLASSES_ROOT\.css

I renamed (by adding leading '--' so that it could be recovered if necessary) keys/records related to .css files association with all applications (including Dreamweaver, Notepad, etc.) and stating .css files as application/x-css type.

After that the issue was resolved and Django CSS styles were correctly applied as it was expected.

Tagliner
  • 94
  • 1
  • 4
  • 1
    Could you kindly state clearly what you renamed. I ran regedit and could not get clearly what i was to rename in those hierarchies – ciira Oct 16 '14 at 08:45
  • In the `HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.css` find following record `Name: Content Type; Type: REG_SZ; Value: application/x-css`, where `Name`, `Type` and `Value` are column headers on the right side of the regedit window. Click at `Content Type`. Call context menu (right button click) and select "Rename". Type `--` before `Content Type` so that the new Name will say `--Content Type`. Repeat the same steps for another record with a `text/css` in the `Value` column. Go to the `HKEY_CLASSES_ROOT\.css`. You will find the same two records. Repeat the same steps. – Tagliner Dec 30 '14 at 12:50
  • it worked great... I also think Dreamweaver had a hand on it because in another machine without Dreamweaver installed it works fine – ciira Jan 29 '15 at 07:15
-1

Setting DEBUG in your setting file fix this:

DEBUG = True
ahmnouira
  • 1,607
  • 13
  • 8