1

When I visit the url of my static files (http://127.0.0.1:8000/site_media/static/css/site_base.css) I receive a 404 error message.

404 from the log

[27/Oct/2012 14:14:54] "GET /site_media/static/js/libs/modernizr-2.5.2.min.js HTTP/1.1" 404 1716
[27/Oct/2012 14:34:20] "GET /site_media/static/css/site_base.css HTTP/1.1" 404 1677

Directory Structure

mysite
    |-- manage.py
    |-- mysite
         |-- settings
             |-- base.py
             |-- dev.py
             |-- prod.py
    |-- site_media
       |-- static
           |-- css
               |-- site_base.css

site_base.html

<link rel="stylesheet" href="{{ STATIC_URL }}css/site_base.css" />

settings

TEMPLATE_CONTEXT_PROCESSORS = [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.static",
]

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
]

STATIC_URL = "/site_media/static/"
STATIC_ROOT = os.path.join(PROJECT_ROOT, "site_media", "static")

Updated:

urls.py

from django.conf import settings
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r"^$", direct_to_template, {'template' : 'home.html' }, name="home"),
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^grappelli/', include('grappelli.urls')),
    url(r'^profile/', include('profiles.urls')),
)

urlpatterns += staticfiles_urlpatterns()
harristrader
  • 1,181
  • 2
  • 13
  • 20
  • Have you configured a `STATIC_URL` and `STATIC_ROOT`? Check out the docs at https://docs.djangoproject.com/en/dev/howto/static-files/. If you have done this, please update those values in the code above, and also post what you get when you do http://127.0.0.1:8000/static/ – zaphod Oct 27 '12 at 19:27
  • yes I have see updated settings above – harristrader Oct 28 '12 at 01:34
  • As mentioned in [the link @jpic provides](https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-development), you need `urlpatterns += staticfiles_urlpatterns()` in your main url conf. Could you post your main `urls.py` and add your `DEBUG` setting? – dokkaebi Oct 28 '12 at 20:34
  • Ive included the main urls file as requested. I have included the additional urls settings and I have not been able to repair this issue. – harristrader Oct 28 '12 at 23:19

2 Answers2

1

Short answer

Django does not serve STATIC_ROOT on STATIC_URL, unless you tell it too.

Long answer

This should be a FAQ, here's an article about using django.contrib.staticfiles right (disclamer: written by me, feedback appreciated). It's like the documentation but tries to be shorter and more pragmatic.

jpic
  • 32,891
  • 5
  • 112
  • 113
1

use <link rel="stylesheet" href="{{ STATIC_URL }}css/site_base.css" /> instead of

<link href="{%static 'css/style.css'%}" rel="stylesheet"> and make sure your value is STATIC_URL = '/static/' in the settings.py

siaka karl
  • 161
  • 2
  • 10