【发布时间】:2012-04-20 00:16:40
【问题描述】:
这是我的设置:
STATIC_ROOT = "/home/tony/Documents/mysite/mysite/"
STATIC_URL = '/static/'
STATICFILES_DIRS = (
"/home/tony/Documents/mysite/mysite/static/",
)
这里我参考了我的样式表(这给了我一个错误):
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/css/reset.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/css/style.css" />
以及日志中的错误:
[06/Apr/2012 13:36:09] "GET /css/reset.css HTTP/1.1" 404 2193
[06/Apr/2012 13:36:09] "GET /css/style.css HTTP/1.1" 404 2193
我认为我是如何解决它的:
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}static/css/reset.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}static/css/style.css" />
它一直有效,直到我换了一个观点-:
from django.shortcuts import render_to_response
from django.template import RequestContext
def test(request):
return render_to_response('test.html')
在模板中我添加了 {% extends 'base/base.html' %} ,我在日志中得到了什么?这个:
[06/Apr/2012 13:46:55] "GET /test/ HTTP/1.1" 200 964
[06/Apr/2012 13:46:55] "GET /test/static/css/style.css HTTP/1.1" 404 2229
[06/Apr/2012 13:46:55] "GET /test/static/css/reset.css HTTP/1.1" 404 2229
注意 /test/?它不会加载 css。
知道为什么吗?(我从来没有遇到过 django1.3 的这个问题)
提前致谢:)
【问题讨论】:
-
我认为 CSS 应该作为媒体而不是静态文件进入
-
@starcorn:这已经改变了。媒体文件现在是已上传的文件,静态文件是 CSS/JS/图像,它们确实是网站本身的一部分。
标签: python django static-files django-staticfiles django-1.4