base.html is used as the base template for all other pages. base.html has the navigation bar and in the navigation bar, I want to show the number of messages the user received. Thus, I need to have a variable like {{number_of_messages}} in the base.html.
However, how should I pass this variable to it? Every template extends base.html and is rendered by a function. I don't think returning number_of_messages in all functions is a good way. Is there better way to implement this? How can I pass this variable to all templates?
TEMPLATE_CONTEXT_PROCESSORSin your settings file. Shall my comments be an answer instead? REF: docs.djangoproject.com/en/dev/ref/templates/api/…context.includetag, does different things, but of course you can pass the context within the included template like{% include "name_snippet.html" with person="Jane" greeting="Hello" %}. But you still need the context somewhere right... docs.djangoproject.com/en/dev/ref/templates/builtins/#include