Is there any way to load a template dynamically inside of a static navbar template based on the current url?
<p>Hi I'm new to django and I'm trying to make a site with it. My project structure is currently like so:  </p>

<pre><code>project/
    manage.py
    project/
        __init__.py
        settings.py
        urls.py
        myapps/
            __init__.py
            main/
                __init__,models,views,urls,etc...
                static/
                    main/
                templates/
                    main/  
</code></pre>

<p>I'm using html5boilerplate with all the css, javascript and images are located in  </p>

<pre><code>myapps/main/static/main/
</code></pre>

<p>And all of my templates reside in  </p>

<pre><code>myapps/main/templates/main/
</code></pre>

<p>With unique names. When the user hits the main page they load up a slightly modified index.html (renamed to boilerplate.html) that came with html5bp:</p>

<pre><code>&lt;!-- boilerplate.html --&gt;
{% load static %}
...
&lt;body&gt;
    &lt;!--[if lt IE 8]&gt;
        ...
    &lt;![endif]--&gt;

    &lt;!-- Add your site or application content here --&gt;
    {% include "main/index.html" %}

    &lt;script src="https://code.jquery.com/jquery-1.12.0.min.js"&gt;&lt;/script&gt;
    &lt;script src="{% static 'main/js/plugins.js' %}"&gt;&lt;/script&gt;
    &lt;script src="{% static 'main/js/main.js' %}"&gt;&lt;/script&gt;

    &lt;!-- Google Analytics: change UA-XXXXX-X to be your site's ID. --&gt;
    &lt;script&gt;
        ...
    &lt;/script&gt;
&lt;/body&gt;
...
</code></pre>

<p>I'm using index.html as my static sidebar but I have it in a separate template in case I want to change it down the line and it separates the boring stuff from the fun stuff (who likes looking at bp code?).  </p>

<pre><code>&lt;!-- index.html --&gt;
&lt;div id="sidenav" class="sidenav"&gt;
    ...
&lt;/div&gt;

&lt;div id="main"&gt;
    {% include /*SOMETHING HERE*/ %}
&lt;/div&gt;
</code></pre>

<p>Now whenever a user is redirected to a new page I just want to resolve the destination url and change the include tag to include a completely different template. So I figured I'd have to pass the requested url to a view function and return a template from that, but I am unsure how to do this or if it would work. Sorry if this is a repeat question from somewhere, I did look and couldn't find anything relevant.</p>

<p>You're thinking about this the wrong way round: you should use template inheritance. Your view should render the specific template for that URL, but each template should in turn extend index.html which provides the sidebar and the rest of the structure.</p>

python django redirect django-templates