Login

Using reverse with success_url in class based generic views

Author:
cdejan
Posted:
May 21, 2011
Language:
Python
Version:
1.3
Score:
3 (after 3 ratings)

If you did tried to use reverse function to set success_url in class based generic views and you have got an exception, this helper function may help.

Put this snipped in some file, for example utils.py and import this function.

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. Add custom fields to the built-in Group model by jmoppel 1 month, 2 weeks ago
  2. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 4 months, 4 weeks ago
  3. Python Django CRUD Example Tutorial by tuts_station 5 months, 1 week ago
  4. Browser-native date input field by kytta 6 months, 3 weeks ago
  5. Generate and render HTML Table by LLyaudet 7 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.

#

Please login first before commenting.