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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…