Django 1.4静态文件问题,不要在我的项目的其他url渲染
问题描述:
这是我的设置:
STATIC_ROOT = "/home/tony/Documents/mysite/mysite/"
STATIC_URL = '/static/'
STATICFILES_DIRS = (
"/home/tony/Documents/mysite/mysite/static/",
)
这里我引用我的样式表(这给我一个错误):
And here I refer my stylesheet(This gives me an error):
<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" />
它工作,直到我再次看到 -
And it worked until I made another view-:
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'%},我在日志中有什么?这个:
And in the template I added the {% extends 'base/base.html' %} and what do I get in the logs? this:
[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)
Notice the /test/? It doesn't load the css.
Any idea why?(I never had this problem with django1.3)
提前感谢:)
答
您没有使用 RequestContext
来渲染您的模板,所以上下文处理器没有被运行,因此 STATIC_URL
是空的。
You're not using RequestContext
to render your template, so the context processors aren't being run and therefore STATIC_URL
is empty.