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/

有帮助吗?

解决方案 2

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'),
) 

其他提示

You can't just drop files into the /static folder of your project. Django doesn't "see" files in that directory unless they were collected from the apps via collectstatic. You will get a 404 trying to access files that you drop in there manually.

You need to put static files into the /static directory of an app (if it doesn't belong in a specific app, just create a new one, for example "main" or "website").

Alternatively you can set the STATICFILES_DIRS for Django to search additional directories when you call collectstatic.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top