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

Contenido del Curso

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

bookImplement Update Functionality

Let's move on to adding the Edit button. While it's a bit more involved than the delete operation, the steps are quite similar.

To get started, begin by defining a new route. We'll create a separate page that enables us to update all the necessary details and save them to the database. Additionally, we'll need to specify both GET and POST methods since we'll be making changes to the database and committing them.

The function redirects back to the same page after clicking the Post button.

As a parameter, we send a recipe that corresponds to the required id, labeled as 'recipe'. This allows us to access the recipe we're editing and autofill the necessary fields.

Now, let's work on our templates. Create an edit.html file inside the templates folder. Copy the relevant blocks from index.html and the form from recipes.html, and paste them into this new file.

The file's name in the example below doesn't correspond to the file's name in our project.

html

index

css

index

js

index

copy

Rename the head inside block head and the title inside the <h2> tag. And add values inside the input tags: value={{ recipe.title }}, and {{ recipe.description }}.

The file's name in the example below doesn't correspond to the file's name in our project.

html

index

css

index

js

index

copy

So, let's check how this page works.

Try to edit some one recipe and check the result.

We have implemented the whole CRUD functionality, and we can READ, CREATE, UPDATE, and DELETE our recipes. Let's improve our style with bootstrap.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 7
We're sorry to hear that something went wrong. What happened?
some-alt