turn standard flask into mvc
Project description
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, e.g:
from flask import Flask
from mvc_flask import FlaskMVC
app = Flask(__name__)
FlaskMVC(app)
Or use application factories
, e.g:
mvc = FlaskMVC()
def create_app():
...
mvc.init_app(app)
By default the mvc_flask
assumes that your application directory will be app
and if it doesn't exist, create it!
You structure should be look like this:
app
├── __ini__.py
├── controllers
│ └── home_controller.py
├── routes.py
└── views
├── index.html
Router
You can create routes in app/routes.py
and after create file, you can start register routes, e.g:
from mvc_flask import Router
Router.get("/", "home#index")
The same must be make done to POST
, PUT
and DELETE
methods. E.g: Router.post("/messages", "messages#create")
The first param represent the relative path and second represent the controller#action
. Remember that we are working with MVC pattern
, so we have controller
and action
.
The controller
can be created in app/controllers
and action is method of controller
.
Controller
Now that configure routes, the home_controller.py
file must contain the HomeController
class, registering the action
, e.g:
from flask import render_template
class HomeController:
def index(self):
return render_template("index.html")
If you have question, please, check de app directory to more details.
Tests
You can run the tests, executing the follow command:
$ make test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for mvc_flask-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d2e907ec2909dc3a4eec393cfc8a4d8d1844f7113d89ba77c1ae98878da561f |
|
MD5 | 9b631b4b560fa0cb038a890a3da97338 |
|
BLAKE2b-256 | b1f7af445c44496cda28d75cc54850c3e3e4be5f93d24d6c95c4e54a6dfab8d3 |