Django templatetags, ImportError

April 16, 2013 - IT

Yesterday I wrote templatetag in Django 1.5. Simple code, about 10 lines. Nothing special. I run runserver, refreshed page and i got error.

ImportError raised loading favorites.templatetags.favorites: No module named models

I checked all path, imports, circural/cross imports. I moved imports to methods. I did small code refactoring. And still the same! Finally, after 1 hour i have found an issue. My django application has the same name as file in templatetag directory. (simple, huh?)

So I had something like this:



from favorites.models import Favorites

In template:

{% load favorites %}

Changing templatetag's filename has fixed the problem.

Maybe it will save someone's time.