views:

39

answers:

1

I'm writing a simple site to display statistics for some data, and I've got an app called "stats", that I'd like to write default templates for (places in stats/templates/stats), but I'd like these to be overridable in the same way that the templates for the admin app are. IE: If I put a stats/view.html in my project's templates directory, it would be used rather than the one in my apps directory. I can't seem to quite figure out how to do this. How can I get Django to search the project's TEMPLATE_DIRS before it hits up the apps?

Edit: Found the problem, saw someone's tutorial for setting the template directories using the os module. They had:

TEMPLATE_DIRS = (
    os.path.join(os.path.basename(__file__), 'templates')
)

Which should be:

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates')
)
+1  A: 

You need to put filesystem loader before app_directories loader in your TEMPLATE_LOADERS setting.

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source'
)

The order of TEMPLATE_LOADERS matter.

muhuk
That looks like what django generated for me, filesystem.load_template_source and then app_directories.load_template_source.Right now I've got ic/templates/stats/view.html and ic/stats/templates/stats/view.html, and it's still rendering the one in the app's template directory.
gct