Using Django template_tag on pages that extend from a view loading a tag

I added a template tag to my application, which I upload in the form located in inc/base.html . This view contains my basic HTML layout. All my other views start with {% extends "inc/base.html" %} .

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

Is this behavior intentional? For example, if I extend the template, does Django intentionally load any of the template tags loaded by the 'parent' template? Is there any reasonable way to globally load my tags?

thanks.

+4
source share
1 answer

This is the correct behavior. The template extension does not load its template tags.

to always load tags, see this answer , although you should carefully consider whether you really want to:

 >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. [...] 
+4
source

Source: https://habr.com/ru/post/1400730/


All Articles