Opened 14 years ago

Closed 11 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

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

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 by Łukasz Rekucki, 14 years ago

Severity: Normal
Type: New feature

comment:3 by tomv2, 14 years ago

Easy pickings: set
Resolution: fixed
Status: newclosed

comment:4 by Tim Graham, 11 years ago

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

comment:5 by Marc Tamlyn <marc.tamlyn@…>, 11 years ago

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