Opened 16 years ago

Closed 16 years ago

#9413 closed (duplicate)

naming a template tag library the same as an app causes import problems

Reported by: Antti Kaihola Owned by: nobody
Component: Documentation Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Django documentation warns about name clashes between custom tag libraries. However, there's no mention about the following problem:

If you have the same name for an app and a tag library, you can't import the app from any other tag libraries. Python first looks up the name among all tag libraries, finds the module there and tries to import that.

This behavior and the incompleteness of the documentation was confirmed by Eric Holscher and lericson on #django-dev a few minutes ago.

Change History (2)

comment:1 by Antti Kaihola, 16 years ago

I had this problem with the photologue re-usable app and had to get this working. So here's a dirty work-around.

Say you have the following file structure under a directory which is in PYTHONPATH:

photologue/
  __init__.py
  models.py
  templatetags/
    __init__.py
    photologue.py
myapp/
  __init__.py
  models.py
  templatetags/
    __init__.py
    myapp_tags.py

In myapp_tags.py, this is going to fail:

from photologue.models import Photo

Instead, you can

photologue_models = __import__('photologue.models', {}, {}, [''])
Photo = photologue_models.Photo

comment:2 by Malcolm Tredinnick, 16 years ago

Resolution: duplicate
Status: newclosed

This is a symptom of #6587.

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