GitHub code size in bytes GitHub Workflow Status GitHub PyPI - Downloads PyPI - Python Version PyPI

You can use the mvc pattern in your flask application using this extension.

Installation

Run the follow command to install mvc_flask:

$ pip install mvc_flask

Configuration

To configure the mvc_flask you need import and register in your application:

from mvc_flask import FlaskMVC
mvc = FlaskMVC()

Or use factory function

mvc = FlaskMVC()

def create_app():
  ...
  mvc.init_app(app)

By default the mvc_flask assumes that your application directory will be app, but, you can change it. Passing the object of configuration:

app.config["FLASK_MVC_DIR"] = "sample_app"

Create MVC Pattern

mvc_flask assumes that your application will have these characteristics:

app
├── __ini__.py
├── controllers
│   └── home_controller.py
├── models
├── routes.json
└── views
    ├── index.html

The routes.json file should be like this:

[
  {
    "method": "GET",
    "path": "/",
    "controller": "home",
    "action": "index"
  },
]

The home_controller.py file should be like this:

from flask.templating import render_template

class HomeController:
    def index(self):
        return render_template("index.html")

Tests

You can run the tests, executing the follow command:

$ make test

GitHub

https://github.com/marcuxyz/mvc_flask