From the course: Advanced Python: Practical Database Examples
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Solution: Develop delete functionality - Python Tutorial
From the course: Advanced Python: Practical Database Examples
Solution: Develop delete functionality
(lively music) - [Instructor] Let's add delete functionality to this application. We'll start by writing the functionality to delete an individual task. The route for this will be delete/task and then the task-id. Technically, this route could be anything you want but I include the task_id because it'll be useful for the implementation to delete the task from the database. Since we'll be deleting data and not retrieving data, we'll make this a POST method. Since we have the task_id handy, we can query the task table and grab the individual task. We save it in a variable called pending_delete. Then we'll use a session object to delete the task. To save these changes, we'll commit them. With the database operations complete, we'll redirect the user to the individual project page. This'll show all the tasks except the one we just deleted. Now, how do we retrieve the original project ID? You might think we have to feed it in…
Contents
-
-
-
-
-
Set up Flask in a Python application2m 20s
-
(Locked)
Create a webpage with Flask2m 52s
-
(Locked)
Build a landing page3m 7s
-
(Locked)
Develop additional routes to enhance your application4m 56s
-
(Locked)
Build a project tasks page2m 16s
-
(Locked)
Create a Postgres database2m 1s
-
(Locked)
Instantiate a Postgres table using Python3m 43s
-
(Locked)
Connect a database to a Python Flask project1m 52s
-
(Locked)
Integrate project data from a Database into Flask2m 57s
-
(Locked)
Integrate task data from a database into a Flask app3m 9s
-
(Locked)
Develop add functionality to add a project5m 7s
-
(Locked)
Develop add functionality to add a task2m 10s
-
(Locked)
Challenge: Develop delete functionality1m
-
(Locked)
Solution: Develop delete functionality7m 13s
-
-