When you need a form to create and edit a record, you donβt have to rewrite the familiar GET/POST view pair. Django already ships two class-based views built for exactly this job β CreateView and UpdateView : just declare the model, the list of fields and the template, and Django handles the rest β rendering the form, validating it, saving and redirecting. These two views fit best when your form maps directly onto a model through a ModelForm .
The Problem
In a blog app, a function-based view for creating a post is usually about 25 lines long: check request.method , build the form from request.POST or an empty form, call is_valid() , save and redirect. The view for editing a post is nearly identical, differing only in the line that fetches the object with get_object_or_404 and passes instance=post .β¦