I have a base.html file in home/templates/home/ and this file contains the header and footer for my home page. The problem I’m having is that the header is not updated when I change it. Initially I copy/pasted from a static html file in another project:
I updated it to replace the portfolio placeholders with an if/else statement wrapping a for loop and added a shop link, but none of this displays in the browser:
<nav id='desktop' class='main-site'>
<ul>
<li><img src="" alt="logo"></li>
<li><a href="index.html">Home</a></li>
<li>About</li>
<li>Store</li>
<li>Portfolio <i class="fas fa-sort-down"></i>
{% if extended_projects_list %}
{% for project in extended_projects_list %}
<!--needs a dynamic link to the project-->
<li><a href="project_link">{{ project.name}}</a></li>
{% endfor %}
{% else %}
<li>No projects available</li>
{% endif %}
</li>
<li><a href="">Blog</a></li>
<li><a href="contact.html">Contact</a></li>
<li><i class="fas fa-search"></i></li>
</ul>
</nav>
I’m betting I’m missing something completely obvious but I’ve been searching for an answer to this and not finding anything close to it.
One of the first things to check is to make sure you don’t have another file named “base.html” anywhere within your project with the old contents.
There’s a very specific order in which directories are searched for files, and if you have two files by the same name, one is going to hide the other.
there’s only one other base.html file and it’s in blog/templates/blog/ and has very different content. I’ve also double and triple checked for a hidden cache and tried running it on a different os (I do my coding in a virtual box and I tried running it on the main os instead). I also tried pushing it to my VPS and running it on my domain and that didn’t work either. It makes seemingly no sense at all. I even tried searching the entire project, every file, for “PH1” and came up empty.
Then the next suggestion is to ensure that your browser is actually fetching a new page and not pulling from cache - try any combination of:
Shift-refresh or Ctrl-F5
Using a different browser
Making the request in “Incognito” or “privacy” mode.
It’s also worth verifying that you’re seeing the request in the server’s console returning a 200 or that you see that request in the browser’s developer tools.
Ok, but one point here is that you’re wondering why PH1 is still showing up.
It’s showing up because it’s in your base template not within a block that will be overridden by the template that extends it.
However, your if extended_projects_listis inside the block header, which is overridden by the empty block header in the index.html file.
You’ve got some interactions between your index.html and base.html that are potentially confusing, but it does explain what you’re seeing.
Also, you have an if extended_projects_list in your template, but if you don’t pass that value to the template in the context, that statement will never be “True”. A template only has access to the variables passed to it in the context.
confusing is definitely the right word here. I haven’t found anyone who can explain to me the interaction between a base template and an extended template. I understand that it somehow combines the two of them but I don’t understand the details of how they combine. Is base.html merged into index.html? or is it the other way around? Do I need the css on both, just base, or just index?
I appreciate your help by the way, thank you. Now that I know where the issue is I know what to look for
I did not know that. I’ll have to look again to see how to pass it in. But beyond that, it’s working perfectly now, and I better understand how it works