Reputation: 11
I'm trying to set up a site in Flask (formerly familiar with django) and I'm having difficulties getting templates to render properly.
I have a base.html, home.html and a navigation.html. My route renders home.html template, which extends the base.html template, and that works fine. But within my base.html, there is another block called navigation. Nothing I enter into my navigation file seems to render at all.
base.html
<DOCTYPE html>
<html>
<head>
<title>{% block title %} {% endblock %} </title>
</head>
<body>
{% block navigation %}
{% endblock %}
{% block content %}
{% endblock %}
</body>
</html>
home.html
{% extends 'base.html %}
{% block title %} lorem ipsum {% endblock %}
{% block content %}
<h1> Here is text </h1>
<p> Lorem ipsum paragraph </p>
{% endblock %}
navigation.html
{% extends 'base.html %}
{% block navigation %}
<nav>
insert any html here, I used a p tag
</nav>
{% endblock %}
I can't get anything within navigation.html to display, no matter what it is. In django, I don't remember having this issue. To my best of critical thinking, I would assume that I'm rendering home.html and not base.html so therefore home.html can use base, but it can't extend it's reach to actually use navigation.html. I'm not sure, and I'm tired of racking my head into my desk.
Upvotes: 0
Views: 547
Reputation: 24966
Making a assumption here, so please clarify if I get this wrong.
I suspect what you mean to do is {% include 'navigation.html' %}
from within index.html
(and in all other pages that want that common navigation).
If that's the case, you can remove the {% extends ... %}
from navigation.html
.
Upvotes: 1