The included urlconf manager.urls doesn't have any patterns in it

让人想犯罪 __ 提交于 2019-11-29 03:01:39

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!