How to create a variable {% extends 'base.html' %}

The objective is to create base template for a {% extends 'base.html' %} that is a function of a request’s path. I’ve tried multiple ways of doing this. The fundamental problem, perhaps, is that no context appears to be created in the view. So clearly I’m well off base. But here’s the simplest thing I’ve done to show that no context is created:

views.py

...
def base_view(request):
    if (5 == 5): 
        info = 'Yes'
    else:
        info = 'No'
    context = { 'info' : info }
    return render(request, "base.html", context)

and
base.html

...
    <body>
        <div>We'd like to let you know that ...</div>
        <div>context value is {{ info }}</div>
        {% block body %}
        {% endblock %}
    </body>
...

which renders as:

We'd like to let you know that ...
context value is

I’ve also tried to replicate this without any success. What am I missing?

PS: If you happen to know how to make visual studio code stop at a breakpoint, I’d love to see it.

What is your urls definition for that view?

What url are you issuing in your browser?

Is there any chance that you have a second “base.html” somewhere in your project?

PS: The two resources that were most helpful to be for this were:

  • urls definition: path('', views.base_view),

  • url in browser? I may be misunderstanding the question; all app templates have {% extends "base.html" %} as their first line.

  • There is only one base.html

base.html exists in diet_project/templates and settings.py includes TEMPLATES = [...'DIRS': [BASE_DIR / 'diet_project/templates'],

And thanks for the references.

Ok, but this view is what you’re testing.

No other view is going to have access to the context that you’re defining in this view. If you’re looking at this by any other url, then this is the expected behavior.

The only url where you would expect to see that context is the url you’re showing for that view.

Well, at least I see why ‘…(I) need to turn (my) perspective “inside out.”’ Next up, try to translate that into appropriate code.

You’re not the first to wrestle with this particular perspective. Most people coming from other frameworks (myself included) have had to make this adjustment.

If I may be so presumptuous, I’d like to suggest you see these posts where I’ve tried to explain some of this to others here:

Thanks immensely for this. What I see now is instead of extending base.html is constructing all of the pieces for base.html in a view. So indeed it is “inside out”, or just about “upside down”. Works very nicely.