[Fixed]-Django – How to send a success message using a UpdateView CBV


To enable the messages in class based views, you need to use the SuccessMessageMixin.

from django.contrib.messages.views import SuccessMessageMixin

class NeedUpdateView(SuccessMessageMixin, UpdateView):
    success_message = 'List successfully saved!!!!'


You can also override the form_valid method like so:

from django.contrib import messages
from django.http import HttpResponseRedirect

class NeedUpdateView(UpdateView):
   def form_valid(self, form):
      messages.success(self.request, "This is my success message")
      return HttpResponseRedirect(self.get_success_url())

Leave a comment