In your settings file:
TEMPLATE_TAGS = ( "djutils.templatetags.sqldebug", )
Make sure load_templatetags() gets called somewhere, for example in your apps init.py
Edit: Updated to work with templatetag libraries that use certain critical django-bits.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | def load_templatetags():
from django.conf import settings
from django.template import add_to_builtins
# This is important: If the function is called early, and some of the custom
# template tags use superclasses of django template tags, or otherwise cause
# the following situation to happen, it is possible that circular imports
# cause problems:
# If any of those superclasses import django.template.loader (for example,
# django.template.loader_tags does this), it will immediately try to register
# some builtins, possibly including some of the superclasses the custom template
# uses. This will then fail because the importing of the modules that contain
# those classes is already in progress (but not yet complete), which means that
# usually the module's register object does not yet exist.
# In other words:
# {custom-templatetag-module} ->
# {django-templatetag-module} ->
# django.template.loader ->
# add_to_builtins(django-templatetag-module)
# <-- django-templatetag-module.register does not yet exist
# It is therefor imperative that django.template.loader gets imported *before*
# any of the templatetags it registers.
import django.template.loader
try:
for lib in settings.TEMPLATE_TAGS:
add_to_builtins(lib)
except AttributeError:
pass
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
This worked for me until I updated my django (svn) when I started getting a crash on startup due to unset ENV variables. I had the code in the main --init--.py (how do you do underscores?) in my project. Moving it to --init--.py in a subdirectory (application) removed the message and made everything happy again.
#
There is a small bug in the import. It should read:
Note additionally that the template tag should be registered as:
#
Please login first before commenting.