[Django] #27570: Make context processor run outside of RequestContext

19 views
Skip to first unread message

Django

unread,
Dec 4, 2016, 4:31:36 AM12/4/16
to django-...@googlegroups.com
#27570: Make context processor run outside of RequestContext
-------------------------------------------+------------------------
Reporter: Anthony King | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
Not all templates are generated within the context of a request, such as
email rendering.
This prevents you accessing variables that are set in your context
processors.

In our codebase, we pass in some settings and other constants via a
context processor, which never looks at the request object.

It would be convenient for those constants to be used in all templates, as
apposed to templates with requests only.


I see 2 possible approaches to adding this functionality:

- Add a constant_processor, however this wrongly limits it to constants.

- make the request argument optional going forward, and use arg
inspections to conditionally context processors for a period.

Using `some_context_processor(request=None)` would show the processor
supports request objects not being set.

--
Ticket URL: <https://code.djangoproject.com/ticket/27570>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 4, 2016, 4:56:57 AM12/4/16
to django-...@googlegroups.com
#27570: Make context processor run outside of RequestContext
---------------------------------+--------------------------------------

Reporter: Anthony King | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Aymeric Augustin):

Quoting myself or #django-dev:

> I would be more happy to support an option to add globals to Django
templates — that could be a simple configuration option — than to start
executing request context processors without a request

> for your own projet, you can create a custom template backend that
inherits the Django template backend, overrides render, and adds your
globals to the context before calling the parent

--
Ticket URL: <https://code.djangoproject.com/ticket/27570#comment:1>

Django

unread,
Dec 5, 2016, 8:21:13 AM12/5/16
to django-...@googlegroups.com
#27570: Make context processor run outside of RequestContext
---------------------------------+--------------------------------------

Reporter: Anthony King | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Tim Graham):

Is adding another way to do this better than using a template tag? You
could add the tag to `TEMPLATES['OPTIONS']['builtins']` to avoid `{% load
... %}` in the template.

--
Ticket URL: <https://code.djangoproject.com/ticket/27570#comment:2>

Django

unread,
Dec 14, 2016, 11:23:05 AM12/14/16
to django-...@googlegroups.com
#27570: Make context processor run outside of RequestContext
---------------------------------+--------------------------------------

Reporter: Anthony King | Owner: nobody
Type: New feature | Status: closed

Component: Template system | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => wontfix


Comment:

Feel free to reopen with an explanation of why the solution I proposed
isn't sufficient.

--
Ticket URL: <https://code.djangoproject.com/ticket/27570#comment:3>

Reply all
Reply to author
Forward
0 new messages