Hello,
What is the best practice in naming templatetags modules in the
following situation?
I have an application named "foo". It lives as a top-level Python
package. Its views are foo.views, its models are foo.models, etc. I
waht this application to define some templatetags. The most logical
name for the tag set would be "foo" - the template author would write
something like "{% load foo %}" to use the tags.
But there's a problem with this naming choice. Say that I need access
to the app's models from inside the templatetags module (which would
be a file named foo/templatetags/foo.py) - I would be writing "from
foo.models import Bar". But that import fails with an interesting
message, telling me there's no module named "foo.models". The reason
for the error is that, when loaded as a templatetags module, the
module is named "django.templatetags.foo", and writing "from
foo.models import Bar" tries to import the symbol "Bar" from the
"django.templatetags.foo.models" module, which does not exist.
As a workaround, I could write "from ..foo.models import Bar", but
that doesn't work in Python 2.3 (which is a problem for me) and it's
also kind of ugly. So the only reasonable solution seems to NOT use
the name "foo" for the templatetags set. That is unfortunate, because
it's the most natural and obvious name to use.
It seems likely that other people have run into this problem; how did
you solve it? Am I missing something?
Cheers,
-- Alex Morega
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---