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.

Integrate project data from a Database into Flask

Integrate project data from a Database into Flask - Python Tutorial

From the course: Advanced Python: Practical Database Examples

Integrate project data from a Database into Flask

- [Instructor] Let's create some database models so we can reference the data from our database and our flask application. We'll create these models using the Model object from our db variable. We'll set the table name to projects and create our columns. For column and integer, we reference the db object to get access to these types, but otherwise, it looks pretty similar to our SQLAlchemy code. In order to access the task data, we'll also need to create a Model class. But first, let's make sure the project data renders as expected. We'll add the functionality so our homepage displays all of our projects. To do this, we'll need to feed our projects into our index.html. We'll add another argument to our render_template call. project.query.all grabs all of the records in our projects table. Since we're using the Flask SQLAlchemy extension, and basing our models off of the db model, we're able to query all of our…

Contents