I have a template, call layout, that is a common header for 10 or so pages. The only thing that changes is the color of one visual, based on the page you are on. I created the layout page which gets all the txt from the SQL DB. Works fine, however if I then try to extend it, none of the text appears, only the background graphics, unless I add the context to the page that extends layout. That seems to be repetitive, as well if I change any item in the header I need to do so over multiple pages. Ideally, all the context would be passed via layout, with any changes done in the individual page templates.
HTML Templates
Layout
{% load static %}
<!DOCTYPE html>
<html lang = "en">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
<title>{{ browsertab }}</title>
</head>
<body>
<h1>{{ dashboard_title }}</h1>
<div class="container" style="top: 5%;">
<div class="item_LoO_Name">
<div class="t1">{{ project }}</div>
<div class="t2">{{ projecttext }}</div>
</div>
<div class="space"></div>
<div class="item_context">{{ area.0 }}</div>
<div class="space"></div>
<div class="item_leadership">{{ area.1 }}</div>
<div class="space"></div>
<div class="item_policy" >{{ area.2 }}</div>
<div class="space"></div>
<div class="item_planning">{{ area.3 }}</div>
<div class="space"></div>
<div class="item_support">{{ area.4 }}</div>
<div class="space"></div>
<div class="item_operation">{{ area.5 }}</div>
<div class="space"></div>
<div class="item_management">{{ area.6 }}</div>
<div class="space"></div>
<div class="item_improvement">{{ area.7 }}</div>
<div class="space"></div>
<div class="triangle-right"></div>
<div class="spaceblank"></div>
<div class="item_LoO_Name" style="background-color: white; color: black;">
<div class="t1">{{outcome}}</div>
<div class="t3">{{ outcometext }}</div>
</div>
</div>
<br>
<p class="t1">{{ areaheader }}</p>
{% block content %}
{% endblock %}
</body>
</html>
leadership
{% extends "ISO22301/layout.html" %}
{% block content %}
<style>
div.item_leadership {
background-color: rgb(211,211,211);
}
</style>
<form action = "" method = "POST">
{% csrf_token %}
</form>
{% endblock %}
views.py
def layout(request):
# all the stuff to create context that is in leadership was initially here
return render(request, "ISO22301/layout.html",)
def leadership(request):
area=Area.objects.all() # get names of areas for header flow diagram
#Name of browser tab
browsertab=list(Dashboard.objects.values_list('company', flat=True))
browsertab=browsertab[0]
#Name of dashboard
dashboard_title=list(Dashboard.objects.values_list('dashboard', flat=True))
dashboard_title=dashboard_title[0]
# names and text for both ends of LoO
project=list(Project.objects.values_list('project', flat=True))
projecttext=list(Project.objects.values_list('project_text', flat=True))
outcome=list(Project.objects.values_list('outcome', flat=True))
outcometext=list(Project.objects.values_list('outcome_text', flat=True))
project=project[0]
projecttext=projecttext[0]
outcome=outcome[0]
outcometext=outcometext[0]
areaheader=Area_Header.objects.all() # get names of areas for header
header=areaheader[1]
print(areaheader)
context = {
"area": area,
"areaheader": header,
"browsertab": browsertab,
"dashboard_title": dashboard_title,
"project": project,
"projecttext": projecttext,
"outcome": outcome,
"outcometext": outcometext,
}
return render(request, "ISO22301/leadership.html", context)