Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Imitating Database | Database
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

bookImitating Database

Let's imitate data as data from the Database, which we will implement later on.

We should pass our list (or database) as an argument, treating it like a table where the keys represent column titles, and each dictionary corresponds to the entries of a row.

The second dictionary does not have an author for a purpose.

To proceed, let's create a new file in the templates directory and name it recipes.html. We'll use this filename as an argument in our function.

Just repeat the code with blocks as in index.html pages.

As we dive into working with several recipes, we'll be passing a list of recipes as an argument. To handle this in Jinja2, we'll harness the power of loops. There are times when we won't know in advance how many items our table will contain, making manual writing impractical. This is where the {% %} syntax for for loops comes to our rescue.

To extract values from the table or dictionary, as we'll do in our scenario, we'll use the double curly brackets, like so: {{ }}.

Furthermore, we can employ the if statement within the same curly brackets and percent sign syntax {% %}. In our case, we'll check whether author information is available in the table, and based on that, we'll either display the author's name or an "N/A" message.

html

index

css

index

js

index

copy

The result is:

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 1
some-alt