Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#925 closed enhancement (fixed)

[patch] Refactor functionality of DjangoContext into 'processors' which can be replaced or added to

Reported by: L.Plant.98@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The attached patch is the result of this discussion on the dev list:


The patch does the following things:

  1. Refactors the functionality of DjangoContext into a bunch of 'request processors'. These are callables that take a request object and return a dictionary to be added to the context.
  2. Allows you to override the request processors that are used by default by changing the REQUEST_PROCESSORS setting
  3. Adds a 'processors' keyword argument to generic views and DjangoContext to allow additional processors to be defined on a per view basis.


Request processors are to template tags what the view function is to templates -- both views and processors process the request object and create data to be added to the context. (Views are different from processors in that they are responsible for returning the HttpResponse object as well, giving them full control and the option to not use the templating system at all etc). Processors are needed to do the processing needed by custom template tags and included sub-templates. The addition of these processors makes it possible to have things like stateful template tags, or other tags that need data from the request object, and have them work in generic views. The patch is totally backwards compatible.


  • DjangoContext is no longer tied to built-in sub-systems.
  • With this patch Django's authentication system becomes more decoupled and replaceable. By simply adding your own version of "django.core.processors.auth" in the REQUEST_PROCESSORS setting, you can plug in your own system and have it available in the template context by default. (In fact, if you wrote an appropriate middleware could replace the built-in one altogether with this patch in place, AFAICT)
  • Part of ticket #667 would be made redundant by this patch (i.e. need for callables in extra_context)

Attachments (1)

request_processors_patch.diff (15.6 KB) - added by L.Plant.98@… 11 years ago.

Download all attachments as: .zip

Change History (7)

Changed 11 years ago by L.Plant.98@…


comment:1 Changed 11 years ago by hugo

Hmm. I think I like this.

comment:2 Changed 11 years ago by rjwittams

Definite +1 from me.

comment:3 Changed 11 years ago by cygnus@…

+1; This sounds great!

comment:4 Changed 11 years ago by anonymous

Summary: Refactor functionality of DjangoContext into 'processors' which can be replaced or added to[patch] Refactor functionality of DjangoContext into 'processors' which can be replaced or added to

comment:5 Changed 11 years ago by rezzrovv


comment:6 Changed 11 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [1773]) Fixed #925 -- Added TEMPLATE_CONTEXT_PROCESSORS, which lets you specify processesors for DjangoContext. Thanks, Luke Plant

Note: See TracTickets for help on using tickets.
Back to Top