Code

Opened 4 years ago

Closed 4 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: UI/UX:

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?

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 4 years ago by russellm

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

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.