37👍
✅
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!!!!'
2👍
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")
super().form_valid(form)
return HttpResponseRedirect(self.get_success_url())
- Email as username in Django
- Django Test Client post() returns 302 despite error on view's post()
- Python/Django: Adding custom model methods?
- Django: Distinct foreign keys
- How to test (using unittest) the HTML output of a Django view?
Source:stackexchange.com