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. "Magic Link" Management Command by webology 3 weeks, 5 days ago
  2. Closest ORM models to a latitude/longitude point by simonw 3 weeks, 5 days ago
  3. Log the time taken to execute each DB query by kennyx46 3 weeks, 5 days ago
  4. django database snippet by ItsRLuo 1 month ago
  5. Serialize a model instance by chriswedgwood 2 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.