Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django template name conflict [duplicate]

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?

like image 629
Alex G.P. Avatar asked Jul 13 '12 12:07

Alex G.P.


1 Answers

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).

like image 169
che Avatar answered Oct 11 '22 10:10

che