Opened 16 years ago

Closed 16 years ago

#6549 closed (duplicate)

Naming templatetag file same as app name can lead to undesired behavior

Reported by: luftyluft@… Owned by: nobody
Component: Template system Version: dev
Severity: Keywords: templatetag
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In a custom template tag, I am attempting to import a model from a 3rd party app. The 3rd party app has a templatetag file named the same as the app (app name=coltrane, tag

If I'm correct in my diagnosis, what's happening is that the
django.templatetags package is altering the import path:

for a in settings.INSTALLED_APPS:
        __path__.extend(__import__(a + '.templatetags', {}, {},
    except ImportError:

We have:


Now when my_tags does an "from coltrane.models import Link", I believe
this is occurring within the scope of django.templatetags and hence
our import path looks like:

(Pdb) import sys
(Pdb) sys.modules['django.templatetags'].__path__
'c:\\documents and settings\\brian\\workspace\\tagging\\templatetags', 
'c:\\documents and settings\\brian\\workspace\\lunnova\\apps\\utils\\templatetags', 
'c:\\documents and settings\\brian\\workspace\\coltrane\\templatetags']

The result is that "from coltrane import Link" is winding up in the coltrane
\templatetags directory, seeing the coltrane module and leading to the
undesired behavior of executing there. I have not seen any
documentation that states that naming templatetag files the same as an
app but it clearly has undesired behavior if a templatetag file tries
to import modules from another app that happens to have a templatetag
file named the same as the app. I will report this as a bug. The
workaround is to rename templatetag files so that they don't clash
with the project name, however it seems like django should perhaps
check for this case and warn the developer or else the documentation
should have a clear warning.

Change History (2)

comment:1 by luftyluft@…, 16 years ago

Summary: Naming templatetag file same can lead to undesired behaviorNaming templatetag file same as app name can lead to undesired behavior

comment:2 by Thomas Güttler, 16 years ago

Resolution: duplicate
Status: newclosed

Please try the patch from #6587 and report there, if it worked for you.

Note: See TracTickets for help on using tickets.
Back to Top