I am using django to create a blog where all posts are shown on the home page as well as on pages depending on their subject. While the basics as shown work, I am having difficulty with the following:
This part of base.html is repeated on each page:
<h1><a href="/">DR SMART.INFO</a></h1>
<p>the web site for the analytical rugby fan</p>
However this part only shows on index.html and not on other pages eg subject.html or post_detail.html
<p>
<ul>
{% for subject in subjects %}
<li><a href="{% url 'subject' subject.subject_slug %}">{{ subject }}</a></li>
{% endfor %}
</ul>
</p>
I would like it to show on the top of each page.
Thanks for assistance with this.
Roderic
base.html
{% load static %}
<html>
<head>
<title>drsmart.info</title>
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
</head>
<body>
<h1><a href="/">DR SMART.INFO</a></h1>
<p>the web site for the analytical rugby fan</p>
<p>
<ul>
{% for subject in subjects %}
<li><a href="{% url 'subject' subject.subject_slug %}">{{ subject }}</a></li>
{% endfor %}
</ul>
</p>
{% block content %}
{% endblock %}
</body>
</html>
index.html
{% extends 'blog/base.html' %}
{% block content %}
{% for post in posts %}
<div>
<h2><a href="{% url 'post_detail' post.slug %}">{{ post.title }}</a></h2>
<p>author: {{post.author}}, published: {{post.date_added }}</p>
<p>{{ post.content|linebreaksbr }}</p>
</div>
{% endfor %}
{% endblock %}
subject.html
{% extends 'blog/base.html' %}
{% block content %}
<h2>{{ subject }}</h2>
{% for post in posts %}
{% if post.subject == subject %}
<div>
<h2><a href="{% url 'post_detail' post.slug %}">{{ post.title }}</a></h2>
<p>author: {{post.author}}, published: {{post.date_added }}</p>
<p>{{ post.content|linebreaksbr }}</p>
</div>
{% endif %}
{% endfor %}
{% endblock %}
post_detail.html
{% extends 'blog/base.html' %}
{% block content %}
<div class="post">
{% if post.date_added %}
<div class="date">
{{ post.date_added }}
</div>
{% endif %}
<h2>{{ post.title }}</h2>
<p>{{ post.content|linebreaksbr }}</p>
</div>
<div class="comments_section">
{{ comments.count }} comments
{% for comment in comments %}
<div class="comments">
{{ comment.name }}
{{ comment.made_on }}
{{ comment.body | linebreaks }}
</div>
{% endfor %}
</div>
<div class="comments_section">
{% if new_comment %}
<div class="alert alert-success" role="alert">
Your comment is awaiting moderation
</div>
{% else %}
Your views? All fields are required. Your email address will not be published.
<form method="post">
{{ comment_form.as_p }}
{% csrf_token %}
<button type="submit" class="btn btn-primary btn-lg">Submit</button>
{% endif %}
</div>
{% endblock %}
Source: Python-3x Questions