Django’s philosophy is about webapps being reusable. But how to achieve template harmony between different webapps?
Here is a hypothetical example: I want to resuse webapp 1 (e.g., django_openid) for OpenID enabled sign-on; and I want to reuse webapp 2 (e.g., django invitation app) for customer invitation; and I want to write my own app (MTV) for statistics
But their templates normally do not look belonging to a single project. How can I reuse the existing work (web app 1 and web app 2 in above hypothetical example) with least intrusive work?
I’m assuming that by ‘intrusive’, you mean editing files within the reusable app.
Without being intrusive at all, you should be able to override any templates in a reusable app, by placing them in a project-level templates directory, or by providing a template with a matching name in an app of your own.
Django template loading is completely configurable, but by default, it will look first in the directory named in settings as
TEMPLATE_DIRS, and then in atemplatesdirectory in each of your installed apps, in the order they appear. By placing your app before openid or invitation in INSTALLED_APPS, then your custom templates will be loaded instead of the supplied ones.In some cases, I have created an “app” for a project, which is actually just an empty models.py and a collection of templates. Then I have a place to store the site base templates, as well as all of the overridden templates from other apps.