Setting a ToDo App Project
Setting a ToDo App Project
Welcome to the first lesson of our course on "Building a ToDo App with Flask." In this lesson, we will guide you through setting up your Flask project, creating a basic project structure, and displaying your first Todo list.
Let's begin by understanding how to structure our project!
Project Overview
Before we dive into coding, it’s essential to understand the structure of our Flask Todo app. Our project will consist of several key components:
- Models: Note that in our context, the
models/directory will contain simple class definitions that represent the data structure of our Todo items. This is not the traditional model layer of MVC architecture but rather a basic class to help us manage our Todo items. - Controllers: In the
controllers/directory, we will define the routes and logic to handle web requests. - Services: In the
services/directory, we'll create the business logic to manage our Todo items. - Templates: The
templates/directory will store the HTML files to render the web pages.
Here is the basic structure of our project:
Creating the Todo Model
A model in Flask is typically a class that represents the data structure of your application. However, it's important to note that in our context, this model does not represent a full-fledged model layer as in MVC architecture. Instead, it's a simple class for managing Todo items.
We'll create a file named app/models/todo.py and we'll add the following content:
This Todo class has three attributes: todo_id, title, and description. This simple class will be the foundation for our Todo items.
Creating the Todo Service
Services are used to handle the business logic of your application. Let's create a service to manage our Todo items.
We'll create a file named app/services/todo_service.py and add the following code:
The TodoService class initializes a list of Todo items and provides a method to retrieve all the todos. This service will simplify managing the Todo items in our application.
