This sounds reasonable, but unfortunately, it's backwards incompatible and
so we cannot make the change. Any URL with a “reason” URL parameter would
no longer be resolvable.

You can make a project-specific shortcut function that allows providing the
reason parameter. Since it’s two lines long, it’s not a huge burden to add.

On Mon, Aug 7, 2023 at 10:48 AM Skrattoune <skratto...@gmail.com> wrote:

> Hi,
>
> I've recently discovered the possibility to add a `reason` to a redirect.
>
> It's extremely useful for testing or debugging when a redirect to a same
> page can have different causes.
>
> I'm proposing to add this functionality to `django.shortcuts.redirect` :
>
> def redirect(to, *args, reason=None, permanent=False, **kwargs):
>     """
>     Return an HttpResponseRedirect to the appropriate URL for the arguments
>     passed.
>
>     The arguments could be:
>
>         * A model: the model's `get_absolute_url()` function will be
> called.
>
>         * A view name, possibly with arguments: `urls.reverse()` will be
> used
>           to reverse-resolve the name.
>
>         * A URL, which will be used as-is for the redirect location.
>
>     Issues a temporary redirect by default; pass permanent=True to issue a
>     permanent redirect.
>
>     a redirect reason can be specified using the `reason` optional
> parameter
>     """
>     redirect_class = HttpResponsePermanentRedirect if permanent else
> HttpResponseRedirect
>     return redirect_class(resolve_url(to, *args, **kwargs), reason=reason)
>
> It does not affect any previous implementation.
> only impact could be if somebody has decided to pass on to a specific page
> the kwarg `reason`
>
> which is extremely minimal risk, and should be anyway easily detected
> through already present testing
>
> Do I have go ahead to propose a PR?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/71d5d7a0-da83-468b-8abb-96478fdcc0e4n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/71d5d7a0-da83-468b-8abb-96478fdcc0e4n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM2PNsHB3OOxS18MJQncN0NkQu-bdYE8Pua%2BhazgOemp4Q%40mail.gmail.com.
  • Add... Skrattoune
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)
      • ... 'Lily Foote' via Django developers (Contributions to Django itself)
        • ... Skrattoune

Reply via email to