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: Melevir Owned by: Melevir
Component: contrib.redirects Version: master
Severity: Normal Keywords: redirects, status_code
Cc: Melevir, unai@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


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 aaugustin 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to New feature
  • Version changed from 1.4 to master

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 aaugustin

comment:2 Changed 4 years ago by aaugustin

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 ryankask

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 unaizalakain

  • Cc unai@… added
  • Has patch set

comment:5 Changed 3 years ago by timo

  • 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 set to fixed
  • Status changed from new to closed

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