Git Product home page Git Product logo

mvc-in-python's Introduction

MVC in Python

This project aims to provide an MVC Python framework for you to use in your projects. If you want to see an example of this framework there is a simple and complete example about a database manager. I believe that this example will make understanding easier of how the mechanics of MVC works in Python, in addition to give you a general view of how to make a project with this pattern.


What is MVC?

Briefly, MVC (Model View Controller) is a design pattern widely used in projects because it leaves the project structured in order to facilitate the identification of application modules, understand how it is structured, in addition to facilitating maintenance. It structures the project in three modules:

Name Funcion
Models Responsible for business logic
View Responsible for the visual part
Controllers Responsible for the behavior of the visual part

How to use this structure in my project?

The core directory contains all classes responsible for MVC operations in Python. If you want to use this structure in your project, you need to know how to use the two classes contained in the core directory: Core (responsible for opening controllers) and Controller (responsible for opening views).

Opening controllers

Core class has a method called "openController", which takes the controller name as a parameter (without including "Controller" in its name). It is crucial that when creating your controllers you follow the following nomenclature:

  • File name: <NameController>Controller.py
  • Class name: NameController

Note that the controller name must starts with a capital letter

Ex - Open src/controllers/HomeController.py
  from core.Core import Core
 
  home = Core.openController("home")
 

All application controllers must extend the "Controller" class, located in src/core/Controller.py. To open a view inside a controller, just call "loadView" method passing the view name as a parameter.

Ex - Open src/views/AddView.py
  from core.Controller import Controller
 
  class AddController(Controller):
    def __init__(self):
        self.addView = self.loadView("add")
 

Views creation

For creating views you must use the following naming pattern:

  • File name: <NameView>View.py
  • Class name: NameView Furthermore, all view classes must extend View class.

Note that the view name must starts with a capital letter

Export for personal project

The contents of the src folder are all you need to apply this pattern to your project.

Overview of a generic MVC Python framework structure

Project organization

The project is in src folder. In it, there are four folders and two files.

/src

Name Type Function
controllers Directory Contains all application controller classes
core Directory Contains the classes responsable for the MVC operations in Python
models Directory Contains all application model classes
views Directory Contains all application view classes
config.py File MVC configuration file (it is important for Core class)
Main.py File File responsible for the application start

/tests

Name Type Function
core Directory Contains all tests related to the Core class

Example

A simple and complete example of an application using this framework can be obtained from the example folder.

mvc-in-python's People

Contributors

williamniemiec avatar goforaditya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.