Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason for this is that the app_directories loader is essentially the same as adding each app's template folder to the TEMPLATE_DIRS setting, e.g. like</p> <pre><code>TEMPLATE_DIRS = ( os.path.join(PROJECT_PATH, 'app1', 'templates'), os.path.join(PROJECT_PATH, 'app2', 'template'), ... os.path.join(PROJECT_PATH, 'templates'), ) </code></pre> <p>The problem with this is that as you mentioned, the index.html will always be found in app1/templates/index.html instead of any other app. There is no easy solution to magically fix this behavior without modifying the app_directories loader and using introspection or passing along app information, which gets a bit complicated. An easier solution:</p> <ul> <li>Keep your settings.py as-is</li> <li>Add a subdirectory in each app's templates folder with the name of the app</li> <li>Use the templates in views like 'app1/index.html' or 'app2/index.html'</li> </ul> <p>For a more concrete example:</p> <pre><code>project app1 templates app1 index.html add.html ... models.py views.py ... app2 ... </code></pre> <p>Then in the views:</p> <pre><code>def index(request): return render_to_response('app1/index.html', locals()) </code></pre> <p>You could even write a wrapper to automate prepending the app name to all your views, and even that could be extended to use introspection, e.g.:</p> <pre><code>def render(template, data=None): return render_to_response(__name__.split(".")[-2] + '/' + template, data) def index(request): return render('index.html', locals()) </code></pre> <p>The _____name_____.split(".")[-2] assumes the file is within a package, so it will turn e.g. 'app1.views' into 'app1' to prepend to the template name. This also assumes a user will never rename your app without also renaming the folder in the templates directory, which may not be a safe assumption to make and in that case just hard-code the name of the folder in the templates directory.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload