Explore my side projects and work using this link

Upsidedown is a WordPress theme design that brings blog posts rising above inverted header and footer components.

Django – UpdateView form_valid() 예외처리

Written in

by

Advertisements

UpdateView 를 이용하여 업데이트 할때, 혹여나 form_valid() 에서 Exception 이 발생하면 그냥 오류 페이지가 떡 떠버린다.

이런거 무시하고 특정 페이지로 무조건 리턴되도록, 즉 예외가 발생하면 update 없이 머 success url 로 이동시키자 이런 코드를 넣어보자. 단순하게 아래처럼 예외를 pass 해버리고 무조건 success_url() 로 이동시키도록 해봤다.

    def form_valid(self, form):        try:            super().form_valid(form)        except Exception as e:            pass        return redirect(self.get_success_url())

form_valid 에서 예외가 나든 안나든 처리가 잘된다. 🙂

끝.

Advertisements