Login

Making templatetags global to all templates

Author:
pryankster
Posted:
April 6, 2007
Language:
Python
Version:
.96
Tags:
tag
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 range filter by zalun 5 years, 11 months ago
  2. Updated - Template context debugger with (I)Pdb by dnordberg 5 years, 6 months ago
  3. Deli.cio.us rss template tag by aaloy 5 years, 10 months ago
  4. google.html template for GoogleAdmin by jbronn 6 years, 4 months ago
  5. google.js template for GoogleAdmin by jbronn 6 years, 4 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.