Chapter 11. Using Views to Add and Update Data in the Database

What You’ll Learn in This Hour

  • requests
  • How to validate data from POST requests against the model
  • How to update data in the database using forms
  • How to add new objects to the database using forms

In Hour 10, “Adding Forms to Views,” you learned how to create Form objects and render them as HTML. In this hour, we will extend that concept and show you how to use rendered forms to update the database.

The following sections take you through the process of displaying the Form during a GET request, retrieving the updated data from the form in a POST request, validating the data, and updating the database.

Handling GET and POST Requests

The first step in using Django Forms to update the database ...

Get Sams Teach Yourself Django in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.