Why use context_processors

Hi Everyone - This is my first post

I want to get a setting from django.conf.settings into a template and the way that seems most obvious to me is to put it in get_context_data as in:

context_data["some_setting"] = settings.SOME_SETTING

but from what I read in a few forums is the recommend way to do it is to use a context processor. Why? Doesn’t that waste resources since the context processor would run for every view even when not needed?

Welcome @tougshire !

This is a decision that you would make depending upon how often it’s needed.

If you only need it in one view, then directly adding it to the context is probably best.

If you need it in many / most views (by relative percentage of access, not by number of views), then you’re likely best off by creating a context processor.

Otherwise, it’s strictly a judgement call depending upon your project.

That makes sense. Thank you!