From the course: Flask Essential Training

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Update and delete operations

Update and delete operations

- [Instructor] Let's build on our simple form example. We'll add functionality to update and delete users directly from the user's list page and save these changes in the database. And to keep things simple, we'll add both update and delete functionality directly on the user list page. That is users template. We're working in app.py, and we're making changes to the user's route. To this route we will add two methods. Get and post method. The user's route now handles both get and post requests. For get requests, it displays the list of users and for post requests, it updates the user's email. When a post request is received, it means the user submitted the update form. This line of code retrieves the user ID from the form data. Then, we retrieve the user email, the new email from the form. Then we find the user in the database by their id. Then we check if the user exists. We update the user's email, we save the changes. And when get request is received, that means user is visiting the…

Contents