I have an app that uses flatpages and other constructs that don’t take a request object. This causes problems in base.html. Here’s a simple example.
If I wanted something like “Welcome {{ request.user.username }}!” at the top of every page, what’s the best way to make that happen?
Flatpages use
RequestContextin rendering templates. Here’s a bit more about RequestContext. Suffice to say, you should be able to write a Context Processor to add request.user to the context of every template. Something like this:Which you would then add to your existing
TEMPLATE_CONTEXT_PROCESSORSin settings.py:You just need to make sure all your views bind
RequestContextto their templates as well:Here’s a good read on Context Processors. They’re a very helpful feature.