Opened 13 years ago

Closed 10 years ago

#15273 closed New feature (fixed)

Extend RedirectView to allow named-URL reversal?

Reported by: Simon Meers Owned by: nobody
Component: Generic views Version: dev
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


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 13 years ago by anonymous

Triage Stage: UnreviewedDesign 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 13 years ago by Łukasz Rekucki

Severity: Normal
Type: New feature

comment:3 Changed 13 years ago by tomv2

Easy pickings: set
Resolution: fixed
Status: newclosed

comment:4 Changed 11 years ago by Tim Graham

Has patch: set
Resolution: fixed
Status: closednew
Triage Stage: Design decision neededUnreviewed
UI/UX: unset

comment:5 Changed 10 years ago by Marc Tamlyn <marc.tamlyn@…>

Resolution: fixed
Status: newclosed

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