开发者

Django: CreateView fail_url

开发者 https://www.devze.com 2023-04-12 14:14 出处:网络
I\'ve the following code and I want form_invalid method to return the same page as success_url. I\'ve been considering sub-classing CreateView but I want to know public opinion.

I've the following code and I want form_invalid method to return the same page as success_url. I've been considering sub-classing CreateView but I want to know public opinion. How to realize the thing described above?

class ProgramNew(CreateView):
    form_class = ProgramForm
    template_name = 'programs/program_list.html'
    success_url = '/manage/programs'

    ....
    ....
    ....

    def form_invalid(self, form):    
        # How to return to self.success_url?
        return super(ProgramNew, self).form_invalid(form)
开发者_如何学C

Sultan


def form_invalid(self, form):    
    return HttpResponseRedirect(self.get_success_url())

But I don't know what's the use of this form.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号