Again on Django template inheritance, children template unaware of father contexts

The difficulty I have is precisely described in

but the answer given there, accepted by the OP, is given in the “recipe” spirit,
as are an incredible number of others I found, concerning the same issue.
Even the django official documentation, having to document an enormously vast field,
suffers from this disease.
So, since I would like not the fish but the fishing rod, please let me restate the question in my terms:

I have a father template and children templates, the latter all filling one block defined
in the father template, one at a time.

The father template is rendered by calling a father-view in father.py, with a father-context, and the view-template relation for the father is given by a line in some urls.py file. This fills up the upper part of the browser screen with some type of “summary data”.

When this is done, it is time to fill up the lower part, with different types of detail information, one at a time of course. I do this with different children views, using in the father-template lines like

{% url ‘djangoapp:details1’ param1_a’%}

or

{% url ‘djangoapp:details2’ param2_a param2_b param2_c %} 

and so on.

These “children views” all generate different “children contexts”, each one of which
is sent to its own “child template”, “{% extend %}” ing the “father template” above.

This works, in the sense that it fills the lower part of my page, but the upper page at this point is full of blank spaces.

I can only guess, this is because the children-contexts do not contain any of the variables I use in the upper part of my page. So I ask:

  1. Is my interpretation correct or am I doing some mistakes? and, if yes,

  2. Am I to fix this by passing in the “url” lines above all parameters received from the father template, totally unneeded by the children views, just for having the children views include them in their children contexts for final transmission to the children templates? (This is, in essence, what the OP was answered in the question in the link above.)

But they are more than 2 or 3, and would clutter everything: the “url” lines above,
the definition of the children views, and also the description lines in the urls.py file.
Since my case seems common enough, I find strange that the django system
of “template inheritance” was not completed by “context inheritance” of some kind.

Thank you for answers, or suggestions.

It’s going to help a lot more if you posted the actual templates you’re trying to use. It’s hard to determine what mistakes you may be making without seeing them.

Also, there is one point to make. Your “main” template extends your base template. However, your main template then uses the include tag to include the child templates being rendered. Those child templates do not use the extends tag.

Thank you for considering my case! Here are my samples: urls.py is:

from django.urls import path
from . import views

urlpatterns = [
    path('father/', views.father, name='father'),
    path('child/<str:singer>', views.child, name='child'),
]

the views:

from django.http import HttpResponse
from django.template import loader
from django.shortcuts import render

# Create your views here.
def father(request):
  template = loader.get_template('father.html')
  context = {
             'singers': {'Peter', 'Paul', 'Mary'},
            }
  return HttpResponse(template.render(context, request))

def child(request,singer):
  template = loader.get_template('child.html')
  context = {
#             'singers': {'Peter', 'Paul', 'Mary'},
             'singer': singer,
            }
  return HttpResponse(template.render(context, request))

the “father” html:

<!DOCTYPE html>
<html>
<body>

<h1>Hello folk-music fan!</h1>
<p>click a singer to get details:!</p>

  {% for singer in singers %}

       <a href="{% url 'child' singer %}"> click {{ singer }} for details</a><br>

  {% endfor %}

  {% block singer_details %}
  {% endblock %}

</body>
</html>

and a child.html:

{% extends 'father.html' %}

{% block singer_details %}
  <h1> Here is {{ singer }}'s bio: </h1>
  <ul>
    <li> bio
    <li> discography
    <li>...
  </ul>
{% endblock %}

my problem is, if I comment the line

#             'singers': {'Peter', 'Paul', 'Mary'},

in the child context, the top part appears blank; if I uncomment it, all works fine; but I do not see why should I do that: the system knows about the template inheritance, why doesn’t it about
a context one? (not trying to be polemic)
Also, this is a toy example: in my real case the child does not have a hard_coded {‘Peter’, ‘Paul’, ‘Mary’} line, that part of the context must be either rebuilt from scratch in the child view, same way as it is done in the father view, or laboriously passed via this line in father.html:

      <a href="{% url 'child' singer %}"> click {{ singer }} for details</a><br>

by disassembling a dictionary into components, to be reassembled later in the child view.
It is quite possible that I misunderstood completely the procedure, but what I am trying to do
now should be clear! Thanks again!

Templates don’t cause things to happen.

Templates are rendered by views.

Your view must produce all data for the context being passed to the rendering engine.

There is no inheritance of context from views.

So, to directly address some of your questions:

Because it doesn’t. That’s not how it was designed to work. Everything is driven by views, not by templates.

As you’ve had it designed, yes.

Your other option, depending upon what the real situation is, would be to have your parent view also obtain the data for the child view, and have your parent template render the child templates using the include tag.

It’s possible, I can’t really address that. However, I do acknowledge that people coming to Django from other frameworks do frequently struggle with template organization.

<opinion>
To the extent of my experience from working with a half-dozen or so web frameworks, Django’s template architecture is different from all the rest, and requires a different perspective on how to best use them. I’ve described the mental process as either turning it upside-down or inside-out. Either way, if you’ve worked with template systems in other frameworks, this probably is going to cause some confusion.
</opinion>

Thank you! This discussion was much useful to me, now I have a better understanding of Django ways.