views:

351

answers:

1

How on earth do people debug Django templatetags?

I created one, based on a working example, my new tag looks the same to me as the existing one. But I just get a

'my_lib' is not a valid tag library: Could not load template library from django.templatetags.my_lib, No module named my_lib

I know that this is probably because of something failing when defining the lib. But how do I see what's going on?

What do you use to debug this situation?

+4  A: 

This sounds like Django can't find the python file your template tag is defined in. Django finds custom tags in a folder named templatetags in your apps folders.

So if you have an app called Books, and you're calling {% load book_tags %} in your template, your Books app folder should look something like this:

  • Books
    • __init__.py
    • views.py
    • models.py
    • templatetags
      • __init__.py
      • book_tags.py

Make sure that __init__.py file is in templatetags.

David
the Books app must also be in the INSTALLED_APPS setting. The template tags loader thingy looks through each 'templatetags' directory in each installed app from top to bottom.
nbv4
Thanks guys. Good advice. Actually I found the problem : my file didn't have the same name as the library being included. Stupidly I assumed that the name in the {% load .. %} was the name of the app.
interstar