Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiate Context, Request Context in django

What is the difference between Context, Request Context in django? Why do we need context processors?

like image 854
whatf Avatar asked Dec 28 '22 07:12

whatf


1 Answers

RequestContext simply goes through your TEMPLATE_CONTEXT_PROCESSORS setting and adds variables in addition to the ones you explicitly pass to the context class.

The context processors are literally just a function that accepts request as the first argument and returns a dictionary to be added into the context.

Why do you need them? Because some very common operations like adding the currently logged in user or STATIC_URL variables to the context would get highly repetitive if not automated.

like image 134
Yuji 'Tomita' Tomita Avatar answered Jan 09 '23 04:01

Yuji 'Tomita' Tomita