djangostatic-filesdjango-1.5

Some static files in django serve 404 when other dont- any ideas why?


Using django 1.5

I got static files configured like this:

STATIC_ROOT = '/home/<user>/Projects/<name>/static'
STATIC_URL = '/static/'

i just run manage.py collectstatic

directory listing:

static/css
static/css/bootstrap.css
static/css/addressbook.css
static/css/bootstrap-responsive.css
static/css/rewrite.css
static/css/login.css

when I type localhost:8000/static/css/addressbook.css i got 404

but:

localhost:8000/static/css/bootstrap.css

gives me a proper css content

WTF? they are in the same folder and have same user/rights/groups

part from menage.py runserver output:

[24/Jul/2013 12:18:19] "GET /static/css/addressbook.css HTTP/1.1" 404 1663
[24/Jul/2013 12:19:16] "GET /static/css/login.css HTTP/1.1" 200 533
[24/Jul/2013 12:20:12] "GET /static/css/addressbook.css HTTP/1.1" 404 1663
[24/Jul/2013 12:32:51] "GET /static/css/bootstrap.css HTTP/1.1" 304 0

UPDATE:

It's serving files not from "project/static" but from static folder under application folder I figure that out by deleting static forder under one app - files start to give 404. Same if I disable AppDirectoriesFinder. But it still not consistent some applications don't serve files even from "static" under application folder.

My ideal situation will be: AppDirectoriesFinder commented out and all files served from myProject/static/


Solution

  • I had the same problem. Here's my solution:

    Add this to your settings.py

    STATICFILES_FINDERS = (
        "django.contrib.staticfiles.finders.FileSystemFinder",
        #"django.contrib.staticfiles.finders.AppDirectoriesFinder"
    )
    
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),
    )