reverse_lazy() in Django
for the classes inherited from generic.edit.CreateView, success_url = url.name does not work because:
Using reverse in your method works because reverse is called when the view is run.
def my_view(request): url = reverse('blog:list-post') ...If you override get_success_url , then you can still use reverse because get_success_url calls reverse when the view is run.
class BlogCreateView(generic.CreateView): ... def get_success_url(self): return reverse('blog:list-post')However, you can’t use reverse with success_url because then reverse is called when the module is imported before the urls have been loaded.
Overriding get_success_url is one option, but the easiest fix is to use reverse_lazy instead of reverse .
from django.core.urlresolvers import reverse_lazy class BlogCreateView(generic.CreateView): ... success_url = reverse_lazy('blog:list-post')