Skip to content

Commit bf270d5

Browse files
committed
Add method to delete task
1 parent 4541e38 commit bf270d5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ def complete_task(task_id): # complete task from task id
149149
return redirect(url_for("index")) # redirect to index page template
150150

151151

152+
@app.route("/delete_task/<int:task_id>")
153+
def delete_task(task_id): # delete task from task id
154+
task = Task.query.get(task_id) # get task by task id
155+
if task:
156+
db.session.delete(task) # delete task from task list
157+
db.session.commit() # commit database changes
158+
return redirect(url_for("index")) # redirect to index page template
159+
160+
152161
def init_db(): # initialize database
153162
with app.app_context():
154163
db.create_all() # create tables if they don't exist

0 commit comments

Comments
 (0)