0

When opening Django admin css of page is not loading.it shows simple page with no css.

my setting.py file is set to:

STATIC_URL = '/static/'
STATIC_ROOT = "C:/Users/AJAY/AppData/Local/Programs/Python/Python36-32/myprograms/mysite/mysite/static/"
STATICFILES_DIRS = [
'C:/Users/AJAY/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/django/contrib/admin/static/',]

my project is in

C:/Users/AJAY/AppData/Local/Programs/Python/Python36-32/myprograms/mysite

try to solve using

 $ python manage.py collectstatic

but could not resolved

installation on my machine are

Python version :3.6.0
Django version :1.10.6

3 Answers 3

1

It might be something in the absolute path. Add this to your settings.py file (if it's not already there).

import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Then, define your STATIC_ROOT

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

Do the same for STATICFILES_DIRS.

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

1 Comment

BASE_DIR is set and I now saw source code in browser which has link tag set to <link rel="stylesheet" type="text/css" href="/static/admin/css/base.css" /> <link rel="stylesheet" type="text/css" href="/static/admin/css/login.css" />
1

You can check the path to your CSS in the browser console (if it doesn't load it should be a 404 - file not found). With that information you should know if the path is wrong (The path is pointing to a place where no such file exists). Use @Nifled 's settings if the path is wrong.

Another idea is that your TEMPLATES list is wrong, try:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
    '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',
        ],
    },
},
]

And the last idea is that you didn't install Django in your virtualenv but in the system. Activate the virtualenv use pip list | grep Django and see if you get an result, if not => you don't have Django installed in the virtual environment.

3 Comments

browser shows error SEC7113: CSS was ignored due to mime type mismatch
now it works fine in firefox but still not working in internet explorer and opera
do you have something like: <!--[if lte IE 8]><link rel="stylesheet" type="text/css" href="{% static 'native_church/css/ie8.css' %}" media="screen" /><![endif]--> ??
1

I added following in my setting.py file and now its working fine:

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

Comments

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.