#32429 closed New feature (wontfix)
Configurable "always available" InclusionNode context variables
Reported by: | Michael Gisi | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 3.1 |
Severity: | Normal | Keywords: | context, inclusion tag, template |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently, the csrf_token
is always added to the context of an inclusion tag. It would be useful to define a list of additional variables that should always be available in any context.
e.g. something like this defined in settings
INCLUSION_CONTEXT_VARIABLES = ['idempotency_key', ]
and a few lines added to the render
method of InclusionNode
def render(self, context): ... csrf_token = context.get('csrf_token') if csrf_token is not None: new_context['csrf_token'] = csrf_token for var in settings.INCLUSION_CONTEXT_VARIABLES: value = context.get(var) if value is not None: new_context[var] = value return t.render(new_context)
Change History (2)
follow-up: 2 comment:1 by , 4 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 4 years ago
Replying to Mariusz Felisiak:
Thanks for this ticket, however creating a new setting is always controversial and we don't want tag-specific settings. The
csrf_token
is a special case (see #12095) to make CSRF protection to be as simple as possible. You can always subclassInclusionNode
and add a custom decorator.
Feel-free to start a discussion on DevelopersMailingList if you don't agree.
Understood - we will subclass InclusionNode
to get the desired behavior. Thanks for the quick response.
Thanks for this ticket, however creating a new setting is always controversial and we don't want tag-specific settings. The
csrf_token
is a special case (see #12095) to make CSRF protection to be as simple as possible. You can always subclassInclusionNode
and add a custom decorator.Feel-free to start a discussion on DevelopersMailingList if you don't agree.