
위 그림과 같이 삭제 버튼을 누르면 나오는 모달의 확인버튼을 누르면 DeleteView의 기본 세팅으로 인해 post_confirm_delete.html이라는 템플릿으로 한번 더 이동하여 삭제를 해야만 했다.
이 과정에서 불편함을 느꼈고, 모달로 한번에 처리하기 위해 관련 자료를 조사한 끝에 시간을 세이브 하였다.
<form class="post-form d-inline" action="{% url 'post_delete' post.pk %}"
method="post">
{% csrf_token %}
<a href="{% url 'post_delete' post.pk %}">
<input type="submit" value="확인" class="btn btn-primary">
</a>
</form>
확인 버튼을 form 태그로 감싸고 post_delete라는 이름의 삭제 클래스 URL과 연결시켰다.
그 다음에 views.py에서 삭제 클래스안에 get함수를 오버라이딩 하였다.
class PostDelete(DeleteView):
model = Post
success_url = reverse_lazy("post_list")
def get(self, request, *args, **kwargs):
return self.post(request, *args, **kwargs)
GET 요청이 들어오면 바로 Post 요청으로 처리하게끔 구현된 코드이다.