A context processor has a very simple interface: It's just a Python function that takes one argument, an HttpRequest
object, and returns a dictionary that gets added to the template context. Each context processor must return a dictionary. Here are a few tips for rolling your own:
Make each context processor responsible for the smallest subset of functionality possible. It's easy to use multiple processors, so you might as well split functionality into logical pieces for future reuse.
Keep in mind that any context processor in
TEMPLATE_CONTEXT_PROCESSORS
will be available in every template powered by that settings file, so try to pick variable names that are unlikely to conflict with variable names your templates might be using independently. As variable names are case-sensitive, it's not a bad idea to use all caps for variables that a processor provides.Custom context processors can live anywhere in your code base. All Django cares about is...