You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 523B

123456789101112131415161718
  1. from django.contrib import messages
  2. class SuccessMessageMixin:
  3. """
  4. Add a success message on successful form submission.
  5. """
  6. success_message = ''
  7. def form_valid(self, form):
  8. response = super().form_valid(form)
  9. success_message = self.get_success_message(form.cleaned_data)
  10. if success_message:
  11. messages.success(self.request, success_message)
  12. return response
  13. def get_success_message(self, cleaned_data):
  14. return self.success_message % cleaned_data