Using reverse with success_url in class based generic views

1
2
3
4
5
6
from django.utils.functional import lazy
from django.core.urlresolvers import reverse

# Workaround for using reverse with success_url in class based generic views
# because direct usage of it throws an exception.
reverse_lazy = lambda name=None, *args : lazy(reverse, str)(name, args=args)

More like this

  1. RestView - class for creating a view that dispatches based on request.method by simon 4 years, 8 months ago
  2. HTTPS redirections middleware with updated URL template tag by xlq 7 months ago
  3. DebugMiddleware footer with links to quick open file/line# in TextMate on local machine by felix_the_third 3 years, 4 months ago
  4. Using reverse() to do redirects by ubernostrum 5 years, 9 months ago
  5. RFC: Shim to allow view classes rather than functions by peterbraden 4 years, 2 months ago

Comments

haplo (on November 13, 2011):

Until Django 1.4 is released and reverse_lazy is included in Django, this snippet does the trick.

#

(Forgotten your password?)