Wouldn't be better to implement this with templatetags? As you said, context processors are for inserting variables for all your templates so, instead of doing that, why not write a templatetag and call whenever you need it?
It's not a bad point but isn't templatetags (that take in the request for context) there to inject content into the template? With template context processors you get *information* which you then deliberately insert into the template when you will.
I get your point. I guess there is a thin line between when to use one or the other in these cases but in my opinion, template tags feel less hacky than using closures for context processors. Mb some1 else can give his opinion ^^.
This is the difference between a filter or simple_tag and an assignment_tag. Definitely agree that if performance is a consideration, this is more cleanly accomplished with an assignment tag.
I don't even know what an "assignment_tag" is. I've been living in Jinja-land so long that maybe this is a newfangled feature in modern Django templates.
Comment
Wouldn't be better to implement this with templatetags? As you said, context processors are for inserting variables for all your templates so, instead of doing that, why not write a templatetag and call whenever you need it?
Replies
It's not a bad point but isn't templatetags (that take in the request for context) there to inject content into the template? With template context processors you get *information* which you then deliberately insert into the template when you will.
I get your point. I guess there is a thin line between when to use one or the other in these cases but in my opinion, template tags feel less hacky than using closures for context processors. Mb some1 else can give his opinion ^^.
This is the difference between a filter or simple_tag and an assignment_tag. Definitely agree that if performance is a consideration, this is more cleanly accomplished with an assignment tag.
I don't even know what an "assignment_tag" is.
I've been living in Jinja-land so long that maybe this is a newfangled feature in modern Django templates.
Even though it was already possible to write such a tag before assignment_tag is indeed a pretty new feature it's only 3 years old https://docs.djangoproject.com/en/1.8/releases/1.4/#assignment-template-tags