Django And The Disappearing Template Tags «
»


Code:
2 comments

If you are defining custom template tags, don’t put them in a file named log.py. You’ll be able to {% load log %} fine in your template, but you won’t be able to use your tags. No, this isn’t documented anywhere.

I suspect it’s because the admin interface also defines custom tags in a file named log.py and that you should avoid duplicating any template tags filename in your INSTALLED_APPS.

This public service announcement has been brought to you by a wasted hour of my life.


Comments

  1. Yeah, it’s due to a conflict in the naming. What’s happening internally is that Django is iterating over INSTALLED_APPS and looking in each app’s directory for a “templatetags” directory; if it finds one, it imports that directory as a Python module under ‘django.templatetags’. Which, of course, means that two tag libraries with the same name will cause a problem.

    I posted about this on django-developers a while back; given that the alternative methods available for finding templatetags libraries would likely impact performance in a bad way, I think this is a “gotcha” I’m OK living with.

Leave a Reply

Your email address will not be published.