Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#19321 closed New feature (fixed)

Add django.contrib.redirects setting for redirect status.

Reported by: Lebedev Ilya Owned by: Lebedev Ilya
Component: contrib.redirects Version: master
Severity: Normal Keywords: redirects, status_code
Cc: Lebedev Ilya, unai@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

At the moment django.contrib.redirects redirects only with status 301(Moved Permanently).
It doesn't allow to use django.contrib.redirects if user needs temporary redirect (one of 302/303/307).
This can be solved easily with with adding optional parameter REDIRECT_STATUS_CODE=301/302/303/307.
It will make redirects middleware more flexible and convenient.

Attachments (1)

19321.patch (1.5 KB) - added by Aymeric Augustin 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by Claude Paroz

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature
Version: 1.4master

The trend is more to add a redirect_class (HttpResponseRedirectBase subclass) attribute instead of setting the status code directly (see #19277). But yes, this seems to be a reasonable feature to add.

Changed 4 years ago by Aymeric Augustin

Attachment: 19321.patch added

comment:2 Changed 4 years ago by Aymeric Augustin

I attached a patch with the general idea.

It'd be nice to make the implementation, tests (and docs if we decide to document this API) consistent between the redirects and locale middleware (#19277).

comment:3 Changed 3 years ago by Ryan Kaskel

I've applied the patch and added tests in this pull request.

I didn't add docs because of the comments in #19277. Is this still the case here?

comment:4 Changed 3 years ago by Unai Zalakain

Cc: unai@… added
Has patch: set

comment:5 Changed 3 years ago by Tim Graham

Needs documentation: set

I think we might as well document these attributes and also include a mention in the release notes.

comment:6 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 8b0014869f666b44cd20692e38073ec0a0a8cb08:

Fixed #19321 -- Allowed redirect middleware HTTP responses to be overridden.

Thanks Melevir for the suggestion.

comment:7 Changed 3 years ago by Tim Graham <timograham@…>

In b798d2bf97a48aac1b0a70e9b3d82457a5212123:

Added versionadded annotations for redirect middleware attributes.

refs #19321

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