Load a Django template tag library for all views by default

Viewed 16859

I have a small typography related templatetag library that I use on almost every page. Right now I need to load it for each template using

{% load nbsp %}

Is there a way to load it "globally" for all views and templates at once? Putting the load tag into a base template doesn't work.

4 Answers

There is an add_to_builtins method in django.template.loader. Just pass it the name of your templatetags module (as a string).

from django.template.loader import add_to_builtins

add_to_builtins('myapp.templatetags.mytagslib')

Now mytagslib is available automatically in any template.

Related