13

Possible Duplicate:
Django view - load template from calling app's dir first

I have Django project with a number of applications. Actually file structure is following:

myproj/
  default/
    templates/
      index.html  (1)
  app1/
    templates/
      index.html  (2)
  app2/
    templates/
      index.html  (3)

I expected that active application's template directory has highest priority when template resolving. But actually I got the first template accordingly to INSTALLED_APPS order! If I changing order of installed apps - template is changed correspondingly.

Question: is there way to get template from current application first? Of uniqueness of template name/explicit directory specification is the only way to achieve it?

Community
  • 1
  • 1
Alex G.P.
  • 9,609
  • 6
  • 46
  • 81
  • 1
    You may want to look at http://stackoverflow.com/questions/3092865/django-view-load-template-from-calling-apps-dir-first – Rohan Jul 13 '12 at 13:00

1 Answers1

14

The usual solution is to put templates in another subdirectory, named after your app, such as:

myproj/
  app1/
    templates/
      app1/
        index.html

This is done by the shipped applications (such as django.contrib.admin) and works pretty well. I usually use generic names like index.html in template root for project-specific files (e.g. the index of the whole site).

che
  • 12,097
  • 7
  • 42
  • 71
  • That's the Django way. I forgot about that and deleted my answer since this is the right answer in my mind. – Jens Jul 13 '12 at 13:01