Answer the question
In order to leave comments, you need to log in
Value from the base on each page?
Good day, gentlemen.
It is necessary to transfer a value from the database to each page of the project. Tell me, please, is it possible to do this without setting the response of this value in each view? Thank you.
Answer the question
In order to leave comments, you need to log in
Good afternoon, yes, you can use Context Processors
1. Create your own Context Processor, like
from games.models import Game
def most_popular_games(request):
return { "MOST_POPULAR_GAMES": Game.objects.filter(active=True).order_by("-rating", "-id")[:5] }
TEMPLATE_CONTEXT_PROCESSORS = (
...
"download_games.context_processors.most_popular_games",
...
}
{% for game in MOST_POPULAR_GAMES %}
...
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question