Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: wontfix
Status: newclosed

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 subclass InclusionNode and add a custom decorator.

Feel-free to start a discussion on DevelopersMailingList if you don't agree.

in reply to:  1 comment:2 by Michael Gisi, 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 subclass InclusionNode 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.

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