[Django]-Why load staticfiles for every template even if it is extended?

30👍

As per Django’s latest documentation, this is done for the sake of maintainability and sanity

When you load a custom tag or filter library, the tags/filters are
only made available to the current template – not any parent or child
templates along the template-inheritance path.

For example, if a template foo.html has {% load humanize %}, a child
template (e.g., one that has {% extends "foo.html" %}) will not have
access to the humanize template tags and filters. The child template
is responsible for its own {% load humanize %}.

This is a feature for the sake of maintainability and sanity.

👤Anupam

3👍

Because that’s the way template tags work. You need to load each library for every template file that uses them.

0👍

It’s logical that you’ll need {% load staticfiles %} wherever you want url expansion to occur. If you have that happening in both base.html & index.html, you’ll have to include it at both places (as you’ve already figured).

👤user

Leave a comment