2👍
1) It looks like you’re on the right track – you have {% block %}
. You just need to have your other files extend that navigation file (you may want to just make it base.html, like the documentation in the link, and have it contain everything all pages should have) and allow those pages to add their own content.
Make it so navigations.html
allows a body:
<html>
{% block side_menu %}
...
{% endblock side_menu %}
<body>
{% block body %}
{% endblock body %}
</body>
</html>
Then at the top of every template:
{% extends 'my_app/navigations.html' %}
with that templates content inside of the {% block body %}
.
2) You can make a template context processor that passes the context to every template. They’re very simple, per the documentation:
It’s a Python function that takes one argument, an HttpRequest object,
and returns a dictionary that gets added to the template context
So:
def my_context_processor(request):
apps = App.objects.all()
return {'app_list': apps}
and in your settings:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Other context processors....
'my_app.processors.my_context_processor',
],
},
},
]
Now in every template, you can do {% for app in app_list %}
without needing your view to return that context.