Opened 8 years ago
Closed 8 years ago
#27570 closed New feature (wontfix)
Make context processor run outside of RequestContext
Reported by: | Anthony King | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
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.
comment:3 by , 8 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Feel free to reopen with an explanation of why the solution I proposed isn't sufficient.
Quoting myself or #django-dev: