If I'm correct in my diagnosis, what's happening is that the django.templatetags package is altering the import path:
#from django.templatetags.__init__.py for a in settings.INSTALLED_APPS: try: __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__) except ImportError: pass We have: /coltrane /templatetags coltrane.py models.py ... /myapp /templatetags my_tags.py 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:\\Python25\\lib\\site-packages\\django-svn\\django\\templatetags', 'C:\\Pyth on25\\lib\\site-packages\\django-svn\\django\\contrib\\admin\ \templatetags', 'c: \\documents and settings\\brian\\workspace\\tagging\\templatetags', 'c: \\documen ts and settings\\brian\\workspace\\lunnova\\apps\\utils\ \templatetags', 'c:\\doc uments and settings\\brian\\workspace\\coltrane\\templatetags'] The result is that "from coltrane" 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. On Feb 4, 6:13 pm, Julien <[EMAIL PROTECTED]> wrote: > Hi Brian, > > I'm facing a similar issue, which is being discussed > here:http://groups.google.com/group/django-users/browse_thread/thread/0ce2... > > I am as surprised as you are by this behaviour... > > On Feb 5, 11:52 am, Brian Luft <[EMAIL PROTECTED]> wrote: > > > Hello, > > > I'm setting up James Bennett's Coltrane app (yes I'm aware that it is > > released as is, with no guarantees). I wrote a templatetag that > > intends to pull all the Links instances and make them available to the > > render context. However, in the tag file, something funny seems to > > happen with the import path. I have: > > > from coltrane.models import Link > > > I get: > > TemplateSyntaxError at /blog/ > > 'coltrane_utils' is not a valid tag library: Could not load template > > library from django.templatetags.coltrane_utils, No module named > > models. I've seen reports that templatetag errors sometimes bubble up > > as something different than what the actual problem is so I dug a > > little deeper. > > > When I did a set_trace, code execution goes from my tag file to: > > /path/to/coltrane/templatetags/coltrane.py. > > > Execution dies when it gets to: > > from coltrane import Entry, Link inside that templatetag file. > > > The question is why is my import statement directing execution to the > > templatetag file in the coltrane app? The expected behavior is that > > execution would go to coltrane/models.py - as verified by testing my > > import statement from the shell. It seems that the templatetag import > > machinery is altering the import path. I tried doing a test using a > > model from an app of my own and did not encounter the same problem. > > Furthermore, if I rename the templatetag file in coltrane (/coltrane/ > > templatetags/coltrane.py) to something else eg. coltrane_tags.py then > > my templatetag works fine. Is it bad practice to name a templatetag > > file the same as the app? Have I discovered a bug? Suggestions, > > workarounds tremendously appreciated. > > > -Brian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---