[Answer]-Unable to convert fully a function based form view to a class based form view

1👍

FormView implements a standard flow for a form, which is to not re-display the populated form after successfully saving it.

To do what you want, you would have to do the form save yourself and then render the view again with the context passed to it, instead of relying on the super-class method to do it.

class ContactFormView(FormView):
    template_name = 'contact.html'
    form_class = ContactForm

    def form_valid(self, form):
        do_something()
        form.save()
        return self.render_to_response(self.get_context_data(form=form))

0👍

form_valid will perform a redirect, not render the template. You’ll need to ditch the default behavior and render the template like you normally would (I assume you’re not saving a model, otherwise you should simply redirect to the url

👤roam

Leave a comment