0

I have problem to load css for admin site. I just setup django 1.8 and run development server but apparently it cannot load css with 500 error code. I cannot figure out what is the problem.

This is my setting.py

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = secret_key

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'rnd.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'rnd.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'rnd.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

this is the error that i get:

Traceback (most recent call last):
  File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 64, in __call__
    return super(StaticFilesHandler, self).__call__(environ, start_response)
  File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 189, i
n __call__
    response = self.get_response(request)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 54, in get_response
    return self.serve(request)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 47, in serve
    return serve(request, self.file_path(request.path), insecure=True)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\views.py", line
 40, in serve
    return static.serve(request, path, document_root=document_root, **kwargs)
  File "C:\Python27\lib\site-packages\django\views\static.py", line 66, in serve

    content_type, encoding = mimetypes.guess_type(fullpath)
  File "C:\Python27\lib\mimetypes.py", line 290, in guess_type
    init()
  File "C:\Python27\lib\mimetypes.py", line 351, in init
    db.read_windows_registry()
  File "C:\Python27\lib\mimetypes.py", line 254, in read_windows_registry
    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
TypeError: must be string without null bytes or None, not str
[08/Jul/2015 11:04:29]"GET /static/admin/css/base.css HTTP/1.1" 500 59

This is url.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
]

The solution:

The root cause for this is because of the corrupted keys in the Windows Registry. I have reinstalled the python 2.7 library and it solved the problem.

7
  • What is the (full) error; please edit your question with the relevant traceback section of the error message. Commented Jul 8, 2015 at 2:37
  • Also, how is your main urls.py set-up? Commented Jul 8, 2015 at 2:37
  • 1
    Uh, I'm not sure how important that secret key is, but you just posted it to the internet. Might be worth switching to a new one now.... Commented Jul 8, 2015 at 3:01
  • evrything is a standard code as we use the startproject command Commented Jul 8, 2015 at 3:07
  • 2
    Could this be helpful? The author complains about corrupted keys in Windows Registry. It also provides links to issues in Python's bugtracker: 22028 and 23604 Commented Jul 8, 2015 at 3:46

1 Answer 1

1

The root cause for this is because of the corrupted keys(have empty string/null value) in the Windows Registry. I have reinstalled the python 2.7 library and it solved the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Some useful background information and possible solutions are available here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.