Skip to content

Brunoenr02/Model-View-Controller-MVC-Pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MVC Pattern Example: Python To-Do List

This repository contains a simple "To-Do List" web application built in Python using the Flask framework. The primary goal of this project is to provide a clear, real-world example of the Model-View-Controller (MVC) architectural pattern, as described in "Patterns of Enterprise Application Architecture."

About This Project

The application's code is intentionally and clearly separated into three distinct components to demonstrate the "Separation of Concerns" principle:

  • Model: Represents the application's data and business logic.
  • View: Represents the User Interface (UI) that the user interacts with.
  • Controller: Acts as the intermediary, receiving user input, interacting with the Model, and updating the View.

Project Structure

The file structure is designed to make the MVC separation explicit:

  • model.py (Model): Contains the TaskModel class. It handles all data and business logic (getting tasks, adding tasks, completing tasks). It has no knowledge of Flask, HTTP, or HTML.
  • templates/index.html (View): The HTML template that defines the UI. It uses Jinja2 syntax to display data it receives from the controller. It contains no business logic.
  • app.py (Controller): Uses Flask to define web routes. It handles user requests (like form submissions), calls methods on the TaskModel, and then renders the index.html View, passing it the necessary data.

Technology Stack

  • Python 3
  • Flask: A micro web framework used to handle the Controller's routing and serve the View.
  • Jinja2: A templating engine (installed with Flask) used by the View.

Getting Started

Follow these instructions to get the project running on your local machine.

Prerequisites

  • Python 3.x
  • pip (Python package installer)

Installation & Running

  1. Clone the repository:

    git clone [https://github.com/Brunoenr02/Model-View-Controller-MVC-Pattern](https://github.com/Brunoenr02/Model-View-Controller-MVC-Pattern)

    (Remember to replace your-username with your actual GitHub username.)

  2. Create and activate a virtual environment (Recommended):

    # For macOS/Linux
    python3 -m venv venv
    source venv/bin/activate
    
    # For Windows
    python -m venv venv
    venv\Scripts\activate
  3. Install the required package (Flask):

    pip install Flask

    (Alternatively, you can create a requirements.txt file, add Flask to it, and run pip install -r requirements.txt)

  4. Run the application:

    python app.py
  5. View the app in your browser: Open your web browser and navigate to: http://127.0.0.1:5000

You will see the To-Do List application running. You can add new tasks and complete existing ones.

License

This project is open-source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published