Writing the Code for the Views
Learn how to write the code for the views.
We'll cover the following...
In this lesson, we add the code for the home page view. To do this, we need to perform the following steps:
- We need to submit the data received from the form to the database if the form inputs are valid.
- We need a way to present the form data on the home page.
- We need to display the empty form for users to enter a new data entry. This has been implemented before, so we’ll cover the first two.
The code for the views
Here’s the complete code for the views:
The Django views
We add some code in the views.py
file. Line 11: We check if the form has been submitted.
Line 13: If it has been submitted, we get data from the form the user filled.
Line 16: We check if the form the user filled is valid using the is_valid()
function. ...