title: Django - how to pass context in base.html?
body: <p>I have <strong>well_list.html</strong> that looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/Br6hh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Br6hh.png" alt="enter image description here"></a></p>
  
  <p>Clicking on one of the rows will lead to this page:</p>
  
  <p><a href="https://i.stack.imgur.com/Io3JB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Io3JB.png" alt="enter image description here"></a></p>
  
  <p>The above page uses two html files: <strong>base.html</strong> + <strong>contextual_main.html</strong>.
  Base has sidebar navigation, and the latter one extends from the base. In my <strong>views.py</strong>, I can easily pass in context data into <strong>contextual_main.html</strong> like this:</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>class ContextualMain_DetailView(DetailView):
      template_name = 'contextual_main.html'
      context_object_name = 'single_well_info'
      model = models.WellInfo
  </code></pre>
  
  <p><strong>contextual_main.html</strong></p>
  
  <pre><code>&lt;button type="button" class="btn btn-default" data-container="body" data-toggle="popover"&gt;
    &lt;a href="{% url 'contextual:bha' pk=single_well_info.api %}"&gt;BHA&lt;/a&gt;
  &lt;/button&gt;
  </code></pre>
  
  <p>I need to inject context, <code>single_well_info</code>, into <strong>base.html</strong> too. So I tried injecting it in the same way I did with contextual_main.html, but it won't work. How can I do this?</p>
  
  <p>edit---------------------------------------------------------------------</p>
  
  <p><strong>base.html:</strong></p>
  
  <pre><code>  &lt;body class="nav-md"&gt;
      &lt;div class="container-fluid body"&gt;
        &lt;div class="main_container"&gt;
          &lt;!-- side bar --&gt;
          &lt;div class="col-md-3"&gt;
            &lt;div class="left_col scroll-view"&gt;
              &lt;!-- sidebar menu --&gt;
              &lt;div id="sidebar-menu" class="main_menu_side hidden-print main_menu"&gt;
                &lt;div class="menu_section"&gt;
                  &lt;ul class="nav side-menu"&gt;
                    &lt;li&gt;&lt;a href="{% url 'well_list' %}"&gt;&lt;i class="fa fa-list-ol"&gt;&lt;/i&gt; Well List &lt;/a&gt;
                    &lt;/li&gt;
                    &lt;li&gt;&lt;a&gt;&lt;i class="fa fa-bookmark"&gt;&lt;/i&gt; My Wells &lt;/a&gt;
                    &lt;/li&gt;
                    &lt;li&gt;&lt;a&gt;&lt;i class="fa fa-dashboard"&gt;&lt;/i&gt; Dashboard &lt;/a&gt;
                    &lt;/li&gt;
                    &lt;li&gt;&lt;a&gt;&lt;i class="fa fa-edit"&gt;&lt;/i&gt; Contextual &lt;span class="fa fa-chevron-down"&gt;&lt;/span&gt;&lt;/a&gt;
                      &lt;ul class="nav child_menu"&gt;
                        &lt;li&gt;&lt;a href="{% url 'contextual:bha' pk=single_well_info.api %}"&gt;BHA&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Integrity Test&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Casing&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Cementing&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Consumables&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Daily Ops&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Logging Data&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Daily Cost&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Mud&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Equipments&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Pumps&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Survey&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Time Log&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Vol &amp; Losses&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Weather&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Well Cond&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Personnels&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                    &lt;/li&gt;
                    &lt;li&gt;&lt;a&gt;&lt;i class="fa fa-clock-o"&gt;&lt;/i&gt; Real Time &lt;span class="fa fa-chevron-down"&gt;&lt;/span&gt;&lt;/a&gt;
                      &lt;ul class="nav child_menu"&gt;
                        &lt;li&gt;&lt;a href=""&gt;Operation&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Beliefs and Alerts&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=""&gt;Drilling Optimization&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/ul&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- /side bar --&gt;
  
          &lt;div class="right_container"&gt;
            &lt;div class="container-fluid"&gt;
              {% block content %} {% endblock %}
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
    &lt;/body&gt;
  </code></pre>
  
  <p>As I was writing editing <code>&lt;a href=""&gt;</code> in <strong>base.html</strong>, my PyCharm IDE recognized <code>contextual:bha</code> argument , but it did not recognize <code>pk=single_well_info.api</code> argument, and that's the trouble. It seems to me that the context is not injected to <strong>base.html</strong>, when <strong>base.html</strong> is extended through <strong>views.py</strong>'s <code>template_name</code> call</p>