Let’s say I have a django site, and a base template for all pages with a footer that I want to display a list of the top 5 products on my site. How would I go about sending that list to the base template to render? Does every view need to send that data to the render_to_response? Should I use a template_tag? How would you do it?
Share
You should use a custom context processor. With this you can set a variable e.g.
top_productsthat will be available in all your templates.E.g.
In your
settings.py:And in your template: