Answer the question
In order to leave comments, you need to log in
How to pass some context to django using template extension?
Hello, I apologize in advance if I'm not explaining the problem clearly.
I have templates in my django project: main-page.html, help-page.html and base.html.
base.html is my navbar, menu bar.
In it, I implemented, in a nutshell, the following code.
<head>
<title>{% block title%} {% endblock %}</title>
</head>
<body>
<nav>
<!-- Тут много строк кода навигационной панели, я его не вставил -->
Новых отчетов <span class="badge badge-pill badge-success">{{ new_report }}</span>
<!-- В "new_report " вставляется из views.py моя переменная о количестве отчетов. -->
</nav>
<main>
{% block content%} {% endblock %}
</main>
</body>
{% extends 'main_application/base.html' %}
{% block title %}
Главная страница
{% endblock %}
{% block content %}
{{ description }}
{% endblock %}
{% extends 'main_application/base.html' %}
{% block title %}
Справка
{% endblock %}
{% block content %}
Данный сайт предназначен для отчетности
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Read the docs, it's all there. Templates do not know how to pass context, they only accept it, for example, from a specific view. There are also context processors https://docs.djangoproject.com/en/3.0/ref/template... that pass context to all templates. This problem can also be solved via https://docs.djangoproject.com/en/3.0/howto/custom...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question