VOOZH about

URL: https://www.geeksforgeeks.org/python/formview-class-based-views-django/

⇱ FormView - Class Based Views Django - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

FormView - Class Based Views Django

Last Updated : 11 Oct, 2025

A FormView is a built-in class-based view used to display and handle forms in Django. Unlike CreateView or UpdateView, FormView does not tie directly to a model by default, making it useful for forms like contact forms, search forms, or any custom form not directly creating a database record.

When using class-based FormView:

  • Specify the form class that will be used.
  • Provide a template to render the form.
  • Define a success URL to redirect after the form is successfully submitted.
  • Optionally, override the form_valid method to handle form data.

Example: Consider a project named Core having an app named books.

Step 1: In core/URLs, set the path for the app.

Step 2: In core/settings.py, add the app name 'books' to the INSTALLED_APPS list

Step 3: In books/admin.py

Step 4: Create a model in books/models.py

Step 5: In books/forms.py, define a form for the model to use in a CreateView

Step 6: After creating the form, create "CreateView" in geeks/views.py

Step 7: Map URL to this view in books/urls.py

Step 8: Set Urls for books/urls.py

Step 9: Create a template for this view in books/add.html

Step 10: Run the app

python manage.py runserver

Visit: http://127.0.0.1:8000/

👁 Image
Snapshot of the development URL
Comment
Article Tags: