Reputation: 6611
I basically need to make a DB query on every view within an app, in order to pass some data to my templates. Since views are not classes, but simple functions, I can't have a construct, where I can do the query.
So, structurally speaking, what is the best practice on where to put this kind of logic? I probably could just create a template tag and do the queries there, but it seems like not very well organized to me.
Upvotes: 0
Views: 38
Reputation: 599628
Firstly, views certainly can be classes: Django has offered class based views since version 1.3.
However, the best way to pass data to every template is to use a context processor.
Upvotes: 2