Django 1.4静态文件问题,不要在我的项目的其他url渲染 [英] Django 1.4 static files problems and don't render at other urls of my project

查看:269
本文介绍了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.

这篇关于Django 1.4静态文件问题,不要在我的项目的其他url渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆