1

I know this question has been asked many times but none of the solutions seems to work for me. I just started using django and I'm having issues trying to get the CSS for the admin panel to show when I use runserver.

When I'm in: localhost:8000/admin/ none of the CSS shows up

<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="/static/admin/css/dashboard.css" />

That is what is shown in the in the HTML of the admin page, which those URL's it links to ends up becoming http://localhost:8000/static/admin/css/base.css which doesn't link to anything.

In settings.py I have

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages',
)

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

STATIC_ROOT = '/Users/datboitom/Sites/Codebase/codebase/codeapp/static/'
STATIC_URL = '/static/'

I'm just not too sure what else to do. If can help me to fix this issue that would be great. I've ran python manage.py collectstatic and the static files are in /Users/datboitom/Sites/Codebase/codebase/codeapp/static/ folder. There just doesn't seem to be any link between these files and whats trying to be loaded. One is trying to load off the localhost url and not the path of where its located on the computer.

arulmr
  • 8,620
  • 9
  • 54
  • 69
datboitom
  • 11
  • 3

5 Answers5

2

Just in case someone run into this error again. While in Debug=False mode, Django won't serve static files for you anymore. Your production server should take care of that. But, if you still want to test your app locally in debug=false you should run the devserver in insecure mode:

manage.py runserver --insecure

Taken from here: Why does DEBUG=False setting make my django Static Files Access fail?

Community
  • 1
  • 1
Carlos Roso
  • 1,435
  • 1
  • 11
  • 14
0

What is your setting like your server?

According to the documentation, you should not write anything at STATIC_ROOT

Leave STATIC_ROOT blank and instead, then, put the path in STATICFILES_DIRS.

Hope this helps

arulmr
  • 8,620
  • 9
  • 54
  • 69
codingdaddy
  • 407
  • 5
  • 17
0

I guess you are missing the following in your settings.py file

# 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',
)
Krishna Balan
  • 256
  • 4
  • 9
0

Config ERROR

in setting.py, you should add 'django.contrib.staticfiles' in INSTALLED_APPS
the codes show:

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

OK,try it.

Community
  • 1
  • 1
Ivan Lyon
  • 1
  • 1
0

I had this problem just recently after changing dev machines.

It turned out that my new machine wasn't set to run django apps in debug mode locally, so adding

DEBUG = True

To my dev machine's settings.py sorted it.

Andrew Calder
  • 451
  • 4
  • 8