using success_url

85 views
Skip to first unread message

Brad Rice

unread,
Jan 10, 2014, 2:36:56 PM1/10/14
to django...@googlegroups.com
I can't seem to find success using success_url

If I try this in my urls.py file

url(r'^step2/', AnswersCreate.as_view(success_url='/requestform/success'), name='answers'),

and then in my view:

def form_valid(self, form):
        obj = form.save(commit=False)
        obj.created_by = self.request.user
        obj.save()
        return HttpResponseRedirect(self.get_success_url())

I get a successful save but it does not take me to the next url defined in success_url

Is there another way to do it, or what am I doing wrong?

trojactory

unread,
Jan 11, 2014, 9:19:34 AM1/11/14
to django...@googlegroups.com
Hi Brad,

If you are using FormView, then you can set the success_url as mentioned in the docs.

Cheers,
Arun

shmengie

unread,
Jan 12, 2014, 9:42:04 AM1/12/14
to django...@googlegroups.com


On Friday, January 10, 2014 2:36:56 PM UTC-5, Brad Rice wrote:
I can't seem to find success using success_url

If I try this in my urls.py file

url(r'^step2/', AnswersCreate.as_view(success_url='/requestform/success'), name='answers'),

and then in my view:

class AnswersCreate(CreateView):
    success_url = '/requstform/success'
    model=myModel
    ...
 
def form_valid(self, form):
        obj = form.save(commit=False)
        obj.created_by = self.request.user
        obj.save()
        return HttpResponseRedirect(self.get_success_url())
 
A mixin may be necessary, to provide get_success_url method added to the class.
Reply all
Reply to author
Forward
0 new messages