Skip to content Skip to sidebar Skip to footer

Django - Messages Functionality Not Working In Class Based View

Unable to display messages in class based view. In another app's views.py, it is working fine where I used function based view. views.py: class PostDeleteView(LoginRequiredMixin, U

Solution 1:

DeleteView does not subclass FormView so SuccessMessageMixin will not do anything. You will have to add the message yourself, overriding the delete method seems like a good place

def delete(self, request, *args, **kwargs):
    response = super().delete(request, *args, **kwargs)
    messages.success(self.request, 'Your post has been deleted sucessfully!')
    return response

Post a Comment for "Django - Messages Functionality Not Working In Class Based View"