Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Implement Delete Functionality | Implement CRUD
Flask Intensive Course: Web Development with Python
course content

Зміст курсу

Flask Intensive Course: Web Development with Python

Flask Intensive Course: Web Development with Python

1. Introduction to Flask
2. Database
3. Implement CRUD
4. FrontEnd Design

book
Implement Delete Functionality

Time to add the DELETE method to our application.

We'll begin by implementing the endpoint first and then move on to the template. This sequence makes the most sense. Let's define a new route for delete and specify which post we intend to remove.

We use the get_or_404() method because we don't want to break if the object does not exist. And after deleting, we need to redirect back to the recipes page.

Next step, we need to have the Delete button on our website. Go to recipes.html. After the description, just put a simple link.

We use the get_or_404() method to prevent any issues in case the object doesn't exist. After deletion, we must redirect back to the /recipes page.

The next step is to add the Delete button to our website. To do this, navigate to recipes.html. Following the description, simply insert a straightforward link after the paragraph with the description.

It's just getting the id of the recipe, then it's fetching that, and it's going to the URL.

Now, refresh it. As you can see, the button becomes active.

If we are going to delete the last recipe, it will be gone.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 6
We're sorry to hear that something went wrong. What happened?
some-alt