![]() |
VOOZH | about |
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:
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/