James Bennett wrote:
> On 6/6/07, Andrew R <[EMAIL PROTECTED]> wrote:
>> whereas I just want it to import "javadoc_filter" from my current dir. I'm 
>> sure
>> this is by design in django but there must be a way around it.
> 
> This is one of the tricky bits of Django that you don't often see.
> Django needs to have some consistent way of locating user-supplied tag
> libraries, so django/templatetags/__init__.py contains a short bit of
> code which loops through INSTALLED_APPS looking for any applications
> which include a "templatetags" module, and extends the import path
> under "django.templatetags" to include those modules.

Wow.

Thanks for this tip - it was the key to solving my problem.

Here is how I solved it (or worked around it), if it is useful to anyone else...

The first thing that is different about my app is that it is just a plain
command line utility that takes input and generates a suite of files using
templates, not a web application. That means that I didn't put my code in a
package or want a settings file.

By using the in-place config code I was able to avoid a django_settings.py file:

>       import django.conf
>       django.conf.settings.configure(
>               TEMPLATE_DIRS =(this_dir),
>       ) 

This worked up until I wanted my own filter.
Adding it under a templatetags dir/package didn't help.

The cause of the problem was that my code wasn't in a package per sae.

Workaround: make it look like my code is in a package.
(I could have actually *put* it in a package, but I didn't want to.)

So, code is under something like: C:\dev\foo\codeGenerator.py
then:

> from django.template import Context, Template, Library
> 
> this_full_dir=os.path.abspath(os.path.dirname(sys.argv[0]))
> this_package_name=os.path.basename(this_full_dir)
> this_container_dir=os.path.abspath(os.path.join(this_full_dir, ".."))
> sys.path.append(this_container_dir)
> 
> import django.conf
> django.conf.settings.configure(
>       TEMPLATE_DIRS =(this_full_dir), # my templates are in the same dir
>       INSTALLED_APPS = (this_package_name),
> ) 

this will automatically make sure that the dir *containing* my code is in the
path and that my pseudo-package is the name of my installed app.

I think a better long term solution is something like:

        Template.add_templatetags_file('filename.py')

But in the absence of that, the above magic works :)

Thanks James + team

Andrew


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to