Reputation: 13
I would like to view some user information on over half of my website's views. This information should contain not only trivial username but also some fields from other tables of my project that are associated with current user. I would also like to put this information into the template that my current view extends, just to keep it DRY. I already did some research and coded some templatetags hoping that registering tags would help me achieve this but I have no idea how to get user information when there's no request like in views' functions. Any tips on how to achieve this will be much appreciated. I just started django yesterday and am still a bit confused by it's philosophy.
Upvotes: 1
Views: 65
Reputation: 34553
You can use a context processor to add data to the template context in a DRY way.
In a nutshell, a context processor is simply a function that accepts a request
as its first argument, does some additional processing that you add and augments the context with whatever values you want.
You can query an objects models, add the current datetime...pretty much anything you can do with Python or Django can go into a context processor.
Upvotes: 1