NoReverseMatch error on redirect

122 views
Skip to first unread message

Brad Rice

unread,
Jan 13, 2014, 12:22:59 PM1/13/14
to django...@googlegroups.com
I have a mulit-page form I am building. I get the start page to enter the data for the application, validate and save. When I try using reverse to move to the next page I get this error:

NoReverseMatch at /requestform/start/Reverse for 'registrant_add' with arguments '()' and keyword arguments '{'app_id': 11}' not found.

I have this url in my urls.py

url(r'^step1/(?P<app_id>\d+)/$, RegistrantCreate.as_view(), name="registrant_add"),

I am trying to call the view this way:

class ApplicationCreate(CreateView):
    model = Application
    form_class = ApplicationForm
    slug_field = 'created_by'
    template_name = 'requestform/start_form.html'

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ApplicationCreate, self).dispatch(*args, **kwargs)


    def form_valid(self, form):
        obj = form.save(commit=False)
        obj.created_by = self.request.user
        obj.created = datetime.datetime.today()
        obj.modified = datetime.datetime.today()
        obj.save()
        return HttpResponseRedirect(reverse('registrant_add', kwargs={'app_id': obj.id}))

Why doesn't django recognize the named url 'registrant_add' and redirect to it?



Brad Rice

unread,
Jan 14, 2014, 8:17:13 AM1/14/14
to django...@googlegroups.com
I figured it out. I had a namespaced url so it needed:

return HttpResponseRedirect(reverse('requestform:registrant_add', kwargs={'app_id': obj.id}))
Reply all
Reply to author
Forward
0 new messages