Using reverse with success_url in class based generic views

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. ModelForm-based create_update generic views by carljm 5 years, 9 months ago
  2. View Redirect Decorators by bryanpieper 3 years, 9 months ago
  3. RelatedMixin for Details and Updates with Related Object Lists by christhekeele 1 year, 11 months ago
  4. RestView - class for creating a view that dispatches based on request.method by simon 5 years, 7 months ago
  5. Class based generic views that automatically check permissions by humphreymurray 3 years, 3 months ago


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?)