Question

I'm getting an Invalid block tag: 'static' error when using a {% static .. %} tag from a template which is {% include %}ed by another template.

The later template has {% load staticfiles %}.
Do I still need to load it again from the included template?

Était-ce utile?

La solution

Yes you do need to load it again. If you look at the docs for the include template tag you will notice:

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”. 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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top