django中的一些静态文件为404提供服务,而其他文件则不为404服务。

时间:2021-10-30 19:21:10

Using django 1.5

使用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

我只是运行管理。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

当我输入localhost:8000 /静态/ css / addressbook。css我有404

but:

但是:

localhost:8000/static/css/bootstrap.css

localhost:8000 /静态/ css / bootstrap.css

gives me a proper css content

给我一个合适的css内容

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

WTF ?它们在同一个文件夹中,具有相同的用户/权限/组。

part from menage.py runserver output:

从家庭的一部分。py runserver输出:

[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.

它提供的文件不是来自“项目/静态”,而是来自应用程序文件夹下的静态文件夹,我通过删除一个应用程序下的静态forder找到的——文件开始提供404。同样,如果我禁用AppDirectoriesFinder。但是它仍然不一致,一些应用程序甚至不提供来自应用程序文件夹下的“静态”文件。

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

我的理想情况是:AppDirectoriesFinder注释掉了所有来自myProject/static/的文件

1 个解决方案

#1


1  

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

我也有同样的问题。这是我的解决方案:

Add this to your settings.py

把这个添加到settings.py中

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    #"django.contrib.staticfiles.finders.AppDirectoriesFinder"
)

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
) 

#1


1  

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

我也有同样的问题。这是我的解决方案:

Add this to your settings.py

把这个添加到settings.py中

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    #"django.contrib.staticfiles.finders.AppDirectoriesFinder"
)

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)