4

I've added a template tag to my app which I load in a view located in inc/base.html. This view contains my basic HTML layout. All my other views begin {% extends "inc/base.html" %}.

In one of my views I want to refer to my template tag, which is loaded in inc/base.html using this code: {% load spb_utils %}. If I try to use on of the template tags inside base.html it works fine, but if I try it any other view, it errors unless I manually add {% load spb_utils %} to the extended view as well.

Is this behaviour intentional? Eg, if I extend a template, does Django deliberately not load any of the template tags the 'parent' template loads? Is there a smart way to globally load my tags?

thanks.

Matt Andrews
  • 2,868
  • 3
  • 31
  • 53

1 Answers1

4

that is the correct behaviour. extending a template does not load its template tags.

for always loading tags, see this answer, though you should carefully consider whether you really want this:

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
[...]
Community
  • 1
  • 1
second
  • 28,029
  • 7
  • 75
  • 76
  • Great, thank you. I realise this removes some of the decoupled nature of Django but at the same time I'm struggling to find a simple, global way to setup (for example) a shared URL variable or whatever. A context processor seems like way more effort than this sort of thing should require. Thanks! – Matt Andrews Mar 10 '12 at 14:28