Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is not clear what you are asking, but as I understand it, your question is:</p> <blockquote> <p>What's the most elegant way to pass the alternate template to the view in bar?</p> </blockquote> <p>This has nothing to do with the url conf, which just maps URLs to methods.</p> <p>Templates in django are looked up from locations in <code>TEMPLATE_DIRS</code> in your settings.py, and most importantly <em>django will stop looking once it finds a template</em>.</p> <p>If your <code>TEMPLATE_DIRS</code> is blank (as is the default), then django will look for templates in a <code>templates</code> directory inside any registered apps (apps listed in <code>INSTALLED_APPS</code>).</p> <p>So, to pass an alternate template to any application, simply create a file with the same name (and directory structure) in a directory that is listed in <code>TEMPLATE_DIRS</code>. Django will search this first, and stop when it finds a match.</p> <p>This is the same way you override default admin templates.</p> <p>For your particular case, suppose you want to pass an alternate version of <code>index.html</code> to the app <code>bar</code>.</p> <p>Create a directory <code>override_templates</code> somewhere in your project path.</p> <p>Inside that create <code>bar/templates/</code> directory, and add your customized <code>index.html</code> to this directory, so you have <code>override_templates/bar/templates/index.html</code>.</p> <p>Add the full path to <code>override_templates</code> to <code>TEMPLATE_DIRS</code> in <code>settings.py</code>.</p> <p>Now django will first search your custom directory for any templates requested, and will load your alternate index.html.</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. 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.
 

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