Do not use appname as templatetags module

Posted on March 30, 2010 in archive, templatetags, django.

This is the second time I created same error writing templatetags, so it is about time to document it.

This is the bad layout for poll app.

polls/
    __init__.py
    models.py
    templatetags/
        __init__.py
        polls.py 
    views.py

Instead of polls.py it should be polls_tags.py or something other different from appname.

Whats going on? polls.py would define polls module and it would not be possible to import other modules from original polls application. For example the code bellow would throw ImportError: No module named models

#polls.py
from django import template

from polls.models import Question

register = template.Library()
Share on Reddit