Tango
Tango

Reputation: 123

django admin css not loading setup

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

Upvotes: 0

Views: 4011

Answers (3)

Tango
Tango

Reputation: 123

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

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

Upvotes: 1

Dawid Dave Kosiński
Dawid Dave Kosiński

Reputation: 901

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.

Upvotes: 1

Nifled
Nifled

Reputation: 452

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.

Upvotes: 1

Related Questions