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. Form field with fixed value by roam 3 days, 20 hours ago
  2. New Snippet! by Antoliny0919 1 week, 3 days ago
  3. Add Toggle Switch Widget to Django Forms by OgliariNatan 2 months, 4 weeks ago
  4. get_object_or_none by azwdevops 6 months, 3 weeks ago
  5. Mask sensitive data from logger by agusmakmun 8 months, 2 weeks 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.