Opened 4 years ago

Closed 23 months ago

#15273 closed New feature (fixed)

Extend RedirectView to allow named-URL reversal?

Reported by: DrMeers Owned by: nobody
Component: Generic views Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

It would be nice to allow named-URL reversal in the new RedirectView.

Example workaround:

class NamedRedirectView(RedirectView):
    url_name = None

    def get_redirect_url(**kwargs):
        if self.url_name:
            return reverse(url_name)
        return super(NamedRedirectView, self).get_redirect_url(**kwargs)
url(r'^blah/', NamedRedirectView.as_view(url_name='xyz:abc')),

I would imagine it is fairly common to want to keep URLconfs DRY, so perhaps this should be built into RedirectView as an additional option? Of course reversing with args/kwargs is a different story altogether...

Change History (5)

comment:1 Changed 4 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

Agreed that it should be easier to do a named URL redirect. The same is true of success URLs on edit views. Whatever solution we come up with should be consistent across all uses if at all possible.

comment:2 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 4 years ago by tomv2

  • Easy pickings set
  • Resolution set to fixed
  • Status changed from new to closed

comment:4 Changed 2 years ago by timo

  • Has patch set
  • Resolution fixed deleted
  • Status changed from closed to new
  • Triage Stage changed from Design decision needed to Unreviewed
  • UI/UX unset

comment:5 Changed 23 months ago by Marc Tamlyn <marc.tamlyn@…>

  • Resolution set to fixed
  • Status changed from new to closed

In b7bd7087e6480c6a071a12ce20b389a8c225e908:

Fixed #15273 -- Extend RedirectView to allow reversal by name.

Thanks to @DrMeers for the report and @ludwigkraatz for the initial patch.

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