django: side menu template visible everywhere
<p>I need to create a side menu in my django admin that should appear in all pages. Ideally my template should be a generic navigation.html file containing this code and parsing app_list param (the same that is used into index.html template populating the dashboard):</p>

<pre><code>{% block side_menu %}
{% if app_list %}
    {% for app in app_list %}
        &lt;ul class="sidebar-menu app-{{ app.app_label }} module"&gt;
         &lt;li class="treeview"&gt;
           &lt;a href="#"&gt;
            &lt;i class="fa fa-dashboard"&gt;&lt;/i&gt; &lt;span&gt;{{ app.name | truncatechars:"25" }}&lt;/span&gt;
            &lt;span class="pull-right-container"&gt;
              &lt;i class="fa fa-angle-left pull-right"&gt;&lt;/i&gt;
            &lt;/span&gt;
          &lt;/a&gt;

        {% for model in app.models %}
        &lt;ul class="treeview-menu"&gt;
            {% if model.admin_url %}
                &lt;li&gt;&lt;a href="{{ model.admin_url }}"&gt;&lt;strong&gt;{{ model.name }}&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
            {% else %}
                &lt;li&gt;{{ model.name }}&lt;/li&gt;
            {% endif %}

            {% if model.add_url %}
                &lt;li&gt;&lt;a href="{{ model.add_url }}"&gt;&lt;i class="fa fa-plus"&gt;&lt;/i&gt; {% trans 'Add' %}&lt;/a&gt;&lt;/li&gt;
            {% else %}
                &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            {% endif %}

            {% if model.admin_url %}
                &lt;li&gt;&lt;a href="{{ model.admin_url }}"&gt;&lt;i class="fa fa-pencil-square-o"&gt;&lt;/i&gt; {% trans 'Change' %}&lt;/a&gt;&lt;/li&gt;
            {% else %}
                &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            {% endif %}
        &lt;/ul&gt;
        {% endfor %}
        &lt;/li&gt;
      &lt;/ul&gt;
    {% endfor %}
{% else %}
    &lt;p&gt;{% trans "You don't have permission to edit anything." %}&lt;/p&gt;
{% endif %}
{% endblock side_menu %}
</code></pre>

<p>My questions are:</p>

<p>1) how can I include my new navigations.html template in all pages?</p>

<p>2) how can I pass to this template the app_list dictionary?</p>

<p>Thanx in advance</p>

<p>1) It looks like <a href="https://docs.djangoproject.com/en/1.10/ref/templates/language/#template-inheritance" rel="nofollow">you're on the right track</a> - you have <code>{% block %}</code>. You just need to have your other files extend that navigation file (you may want to just make it base.html, like the documentation in the link, and have it contain everything all pages should have) and allow those pages to add their own content.</p>

<p>Make it so <code>navigations.html</code> allows a body:</p>

<pre><code>&lt;html&gt;
    {% block side_menu %}
        ...
    {% endblock side_menu %}
    &lt;body&gt;
        {% block body %}
        {% endblock body %}
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Then at the top of every template:</p>

<pre><code>{% extends 'my_app/navigations.html' %}
</code></pre>

<p>with that templates content inside of the <code>{% block body %}</code>.</p>

<p>2) You can <a href="https://docs.djangoproject.com/en/1.10/ref/templates/api/#writing-your-own-context-processors" rel="nofollow">make a template context processor</a> that passes the context to every template. They're very simple, per the documentation:</p>

<blockquote>
  <p>Itâs a Python function that takes one argument, an HttpRequest object,
  and returns a dictionary that gets added to the template context</p>
</blockquote>

<p>So:</p>

<pre><code>def my_context_processor(request):
    apps = App.objects.all()
    return {'app_list': apps}
</code></pre>

<p>and in your settings:</p>

<pre><code>TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Other context processors....
                'my_app.processors.my_context_processor',
            ],
        },
    },
]
</code></pre>

<p>Now in every template, you can do <code>{% for app in app_list %}</code> without needing your view to return that context.</p>

python django