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.
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.
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.