[Django]-Django FormView vs CreateView

22👍

From Django-docs:

FormView:

A view that displays a form. On error, redisplays the form with
validation errors; on success, redirects to a new URL.

It can be used for various purposes and is not restricted to creating objects. A nice example would be using it as a contact form and sending emails without creating records in database.

CreateView:

A view that displays a form for creating an object, redisplaying the
form with validation errors (if there are any) and saving the object.

The sole purpose of this generic view is to create objects. But it is not limited to creating objects. You can send emails from this view too (just like FormView)

If your FormView creates model objects, it is best to use CreateView and not creating a modelform, that’s what generic views are for, reducing repetition.

👤v1k45

Leave a comment