问题描述
这表明我可以在我的模板中使用 STATIC_URL
来获取价值来自settings.py。
This suggests that I can use STATIC_URL
in my template to get the value from settings.py.
模板如下所示:
<link href="{{STATIC_URL}}stylesheets/tabs.css" rel="stylesheet" type="text/css" media="screen" />
Settings.py如下所示:
Settings.py looks like this:
STATIC_ROOT = ''
STATIC_URL = '/static/'
当我去页面时,我刚刚得到< link href =stylesheets / tabs.css
ie no STATIC_URL。
When I go to the page I just get <link href="stylesheets/tabs.css"
i.e. no STATIC_URL.
我缺少什么?
推荐答案
你必须使用 context_instance = RequestContext (请求)
在 render_to_response
中,例如:
You have to use context_instance=RequestContext(request)
in your render_to_response
, for example:
return render_to_response('my_template.html',
my_data_dictionary,
context_instance=RequestContext(request))
或使用新的快捷方式
正如Dave指出的,您应该检查 django.core.context_processors.static
是否在您的 TEMPLATE_CONTEX settings.py中的T_PROCESSORS
变量。如所述,它在这里默认情况下。
As Dave pointed out, you should check if django.core.context_processors.static
is in your TEMPLATE_CONTEXT_PROCESSORS
variable in settings.py. As the docs said, it`s there by default.
这篇关于Django:无法从模板中的设置中呈现STATIC_URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!