Skip to main content

turn standard flask into mvc

Project description

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
│   ├── contact_controller.py
│   └── home_controller.py
├── model
├── routes.json
└── views
    ├── index.html
    └── post
        └── new.html

The routes will be something as:

[
  {
    "method": "GET",
    "path": "/",
    "controller": "home",
    "action": "index"
  },
  {
    "method": "get",
    "path": "/new",
    "controller": "home",
    "action": "new"
  },
  {
    "method": "post",
    "path": "/create",
    "controller": "home",
    "action": "create"
  },
  {
    "method": "GET",
    "path": "/contact",
    "controller": "contact",
    "action": "index"
  }
]

Tests

You can run the tests, executing the follow command:

$ make test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mvc-flask-1.0.1.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

mvc_flask-1.0.1-py3-none-any.whl (2.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page