It blows me away how common this is. You want to use context processors my friend!
Very easy to create, like so:
def messagenumber_processor(request):
return {'messagenumber': 5}
Since messagenumber is a dynamic variable based on the User, you could pull data from the database by fetching from request.user
as you have full access to request
within each context processor.
Then, add that to your TEMPLATE_CONTEXT_PROCESSORS
within settings.py and you're all set :-) You can do any form of database operation or other logic within the context processor as well, try it out!