I have a Django 1.6 application using Postgres 9.3. Every template for every view on the site will extend one or the other of two templates. One template "anon.html" will display a minimal page header on all pages a user who is not signed in can view (e.g. during the signup process when the user doesn't have an account yet). The second "auth.html" template is extended in every template that is displayed when a logged-in user is viewing a page. This template displays a header containing links such as "Show Members", "Messages", "Account" and so forth. Any view that renders this template will be prefaced with the @login_required decorator. How do I execute a Django database query each time a user requests a page that requires them to be logged in (in other words), when I render the "auth.html" template? If the user has new messages, I want to be able to change the "Messages" link in the auth.html template header to say "New Messages". This query has to run before the rest of the page is rendered and I don't want to put the query in every view.
Thanks!