Opened 15 years ago

Closed 14 years ago

#13753 closed (fixed)

Generic views don't redirect to an URL name, like django.shortcuts.redirect does

Reported by: Diederik van der Boor <vdboor@…> Owned by: nobody
Component: Generic views Version: 1.2
Severity: Keywords: redirect DRY
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I just noticed that the post_save_redirect parameter of generic views (update_object, and friend) doesn't have the same abilities as django.shortcuts.redirect (in fact, it reinvents the wheel).
When an URL name is passed, it will not do a lookup, but redirect to that given name.


The following does not work as expected:

def edit(request, item_id):
    return update_object(request, object_id=item_id, model=Context
                                  post_save_redirect='myapp-context-index')

It needs a manual resolve call:

from django.core import urlresolvers

def edit(request, item_id):
    return update_object(request, object_id=item_id, model=Context
                                  post_save_redirect=urlresolves.reverse('myapp-context-index'))   # manual resolving

Unlike the django.shortcuts.redirect function, which does allow the URL name to be used:

    return redirect("myapp-context-index")

In other words, could the generic view use django.shortcuts.redirect internally too?

Change History (2)

comment:1 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

A reasonable suggestion; however, it may be better to integrate this into the #6735 rewrite of generic views, rather than work on a patch against the current generics.

comment:2 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

Function-based generic views were deprecated by the introduction of class-based views in [14254]. Class-based views should solve this problem.

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