Thanks for weighing in, that is helpful, and last night I was playing around 
with a somewhat similar approach. It's not exactly what I was hoping for, 
because it still isn't really integrated with the way Django uses template 
loaders.

This solution works for TEMPLATE_DIRS and INSTALLED_APPS, but there are other 
possible template loaders, or a user might have written a custom template 
loader. Or they may have disabled the app directories loader… Anyway, you get 
the idea.

If the built-in loader classes had some method that would just return the paths 
to the template directories that were loaded, this could work perfectly, but I 
think the loaders can only check to see if a supplied template name exists on 
one of the paths they serve. So it seems like my idea is not really feasible in 
a way that integrates cleanly with Django and results in a portable 
application. Thanks to everyone who replied with assistance.

- Patrick


On Saturday, February 11, 2012 at 5:39 AM, bb6xt wrote:

> Here's my two cents. Hope it helps some.
>  
> from proj.settings import TEMPLATE_DIRS, INSTALLED_APPS
> import os
>  
> def recursive_search(path):
> result = []
> for i in os.listdir(path):
> if not os.path.isdir(os.path.join(path, i)):
> result.append(i)
> else:
> result.extend(recursive_search(os.path.join(path, i)))
> return result
>  
> def myview(request):
> templates = []
> # the next 2 lines handles templates in explicit template
> directories
> for path in TEMPLATE_DIRS:
> templates.extend(recursive_search(path))
> # the next 2 will handle template dir generated py the
> appdirectories loader excluding contrib apps
> for app in INSTALLED_APPS:
> if app.startswith('proj'):
> if os.path.exists(os.path.join(ABSPATH_TO_PROJ,
> app.split('.')[-1], 'templates')):
>  
> templates.extend(recursive_search(os.path.join(ABSPATH_TO_PROJ,
> app.split('.')[-1], 'templates')))
>  
> well, you have a list of templates with which you can do as you
> please. surely you'll want to keep track of the actual path django
> uses to locate these templates, you can do so by tweaking the
> recursive_search funct a little
>  
>  

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to