简体   繁体   English

使用“包含”模板中的“静态”模板标签?

[英]using “static” template tag from “included” template?

I'm getting an Invalid block tag: 'static' error when using a {% static .. %} tag from a template which is {% include %}ed by another template. 我收到了一个Invalid block tag: 'static'当使用来自另一个模板{% include %}ed的模板的{% static .. %}标记时出现Invalid block tag: 'static'错误。

The later template has {% load staticfiles %} . 后面的模板有{% load staticfiles %}
Do I still need to load it again from the included template? 我还需要从附带的模板中再次加载吗?

Yes you do need to load it again. 是的,你需要再次加载它。 If you look at the docs for the include template tag you will notice: 如果您查看include模板标记的文档,您会注意到:

The include tag should be considered as an implementation of “render this subtemplate and include the HTML”, not as “parse this subtemplate and include its contents as if it were part of the parent”. include标记应该被视为“渲染此子模板并包含HTML”的实现,而不是“解析此子模板并将其内容包含在内,就好像它是父类的一部分”。 This means that there is no shared state between included templates – each include is a completely independent rendering process. 这意味着包含的模板之间没有共享状态 - 每个包含都是完全独立的渲染过程。

Note that the template you are loading uses the context of the parent template, so that's why you still have access to all the variables of the parent tepmlate 请注意,您正在加载的模板使用父模板的上下文,这就是为什么您仍然可以访问父tepmlate的所有变量的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM