django form views tutorial code example

Example: django form view

class ContactView(FormView):
    form_class = ContactForm
    template_name = 'contact-us.html'
    success_url = reverse_lazy('<app_name>:contact-us')

    def get_initial(self):
        initial = super(ContactView, self).get_initial()
        if self.request.user.is_authenticated:
            initial.update({'name': self.request.user.get_full_name()})
        return initial

    def form_valid(self, form):
        self.send_mail(form.cleaned_data)
        return super(ContactView, self).form_valid(form)

    def send_mail(self, valid_data):
        # Send mail logic
        print(valid_data)