Login

Making templatetags global to all templates

Author:
pryankster
Posted:
April 6, 2007
Language:
Python
Version:
.96
Score:
11 (after 11 ratings)

I found myself putting {%load ... %} in every template that I was writing, so DRY .. I created an app called 'globaltags' and in its __init__.py, I just pre-load the tags that I use frequently.

The pyif and expr tags are excellent tags, and I highly recommend them for getting the most out of django's template language.

The dbinfo snippet is something that I came up with to easily output SQL debugging information.

1
2
3
4
5
6
# <mysite>/globaltags/__init__.py

from django.template import add_to_builtins
add_to_builtins('globaltags.pyif')
add_to_builtins('globaltags.expr')
add_to_builtins('globaltags.dbinfo')

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

gsf0 (on August 27, 2007):

Took me a second to realize I still had to add '<mysite>.globaltags' to INSTALLED_APPS, then it worked like a charm! Thanks.

#

Please login first before commenting.