[Django]-The included urlconf manager.urls doesn't have any patterns in it

53👍

The problem is that your URLConf hasn’t finished loading before your class based view attempts to reverse the URL (AddObjView.success_url). You have two options if you want to continue using reverse in your class based views:

a) You can create a get_success_url() method to your class and do the reverse from there

class AddObjView(CreateView):
    form_class = ObjForm
    template_name = 'manager/obj_add.html'

    def get_success_url():
        return reverse('manager-personal_objs')

b) If you are running on the trunk/dev version of Django, then you can use reverse_lazy https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-lazy

from django.core.urlresolvers import reverse_lazy

class AddObjView(CreateView):
    form_class = ObjForm
    template_name = 'manager/obj_add.html'
    success_url = reverse_lazy('manager-personal_objs')

Option “b” is the preferred method of doing this in future versions of Django.

👤erikcw

Leave a comment