All Projects → marcuxyz → mvc-flask

marcuxyz / mvc-flask

Licence: MIT License
You can use the mvc pattern in your flask application using this extension.

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects
HTML
75241 projects

Projects that are alternatives of or similar to mvc-flask

Flask And Redis
Simple as dead support of Redis database for Flask applications
Stars: ✭ 76 (+192.31%)
Mutual labels:  flask-extensions
flask-diced
Flask-Diced - CRUD views generator for Flask
Stars: ✭ 15 (-42.31%)
Mutual labels:  flask-extensions
flask-pwa
A extension to give a PWA experience into your Flask app.
Stars: ✭ 23 (-11.54%)
Mutual labels:  flask-extensions
Flask Ask
Alexa Skills Kit for Python
Stars: ✭ 1,877 (+7119.23%)
Mutual labels:  flask-extensions
Flask-CSV
Easily render CSVs within any flask application
Stars: ✭ 20 (-23.08%)
Mutual labels:  flask-extensions
flask-jwt-login
Flask extension that helps authentication using JWT (for a personal purpose, not maintained now)
Stars: ✭ 12 (-53.85%)
Mutual labels:  flask-extensions
Flask Htmlmin
Flask html response minifier
Stars: ✭ 66 (+153.85%)
Mutual labels:  flask-extensions
flask-simplemde
Flask-SimpleMDE - a Flask extension for SimpleMDE
Stars: ✭ 23 (-11.54%)
Mutual labels:  flask-extensions
flask url discovery
Flask extension for discovering urls in a service. Automatically expose urls for a service. Manage urls exposure settings.
Stars: ✭ 13 (-50%)
Mutual labels:  flask-extensions
flask-funnel
Better asset management for Flask
Stars: ✭ 22 (-15.38%)
Mutual labels:  flask-extensions
Flask Jsonrpc
A basic JSON-RPC implementation for your Flask-powered sites
Stars: ✭ 223 (+757.69%)
Mutual labels:  flask-extensions
Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+10765.38%)
Mutual labels:  flask-extensions
Flask-QRcode
A concise Flask extension to easily render QR codes on Jinja2 templates using python-qrcode.
Stars: ✭ 89 (+242.31%)
Mutual labels:  flask-extensions
Flask simplelogin
Simple Login - Login Extension for Flask - maintainer @cuducos
Stars: ✭ 133 (+411.54%)
Mutual labels:  flask-extensions
flask-stupe
💉 a.k.a. « Flask on steroids »
Stars: ✭ 30 (+15.38%)
Mutual labels:  flask-extensions
Flask Mobility
A Flask extension to simplify building mobile-friendly sites.
Stars: ✭ 68 (+161.54%)
Mutual labels:  flask-extensions
flask-vuejs
Connect Flask application with VueJS
Stars: ✭ 29 (+11.54%)
Mutual labels:  flask-extensions
flask-graphite
📈 Push useful metrics for each request without effort!
Stars: ✭ 15 (-42.31%)
Mutual labels:  flask-extensions
flaskerk
A flask extension for api doc and validation of request&response.
Stars: ✭ 24 (-7.69%)
Mutual labels:  flask-extensions
Flask-GraphQL-Auth
(UNMAINTAINED. FEEL FREE TO FORK) 🐍A Pythonic way to provide JWT authentication for Flask-GraphQL
Stars: ✭ 64 (+146.15%)
Mutual labels:  flask-extensions

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.

This real world implementation FLASK MVC example: https://github.com/negrosdev/negros.dev

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.

You can use Router.all() to register all routes of CRUD.

Router.all("users")

The previous command produce this:

users.create     POST     /users
users.delete     DELETE   /users/<id>
users.edit       GET      /users/<id>/edit
users.index      GET      /users
users.new        GET      /users/new
users.show       GET      /users/<id>
users.update     PUT      /users/<id>

You can also use only parameter to controll routes, e.g:

Router.all("messages", only="index show new create")

The previous command produce this:

messages.create  POST     /messages
messages.index   GET      /messages
messages.new     GET      /messages/new
messages.show    GET      /messages/<id>

The paramenter only accept string or array, so, you can use only=["index", "show", "new", "create"]

Controller

Now that configure routes, the home_controller.py file must contain the HomeController class, registering the action, e.g:

class HomeController:
    def index(self, view, request):
        return view("index.html")

If you have question, please, check de app directory to more details.

To use the hooks as before_request, after_request and etc... Just describe it in the controller, see:

class HomeController:
    before_request = ["hi"]

    def index(self, view, request):
        return "home"

    def hi(self):
        ...

The previous example describes the hi(self) will be called every times that the visitors access the controller.

Views

Flask use the templates directory by default to store HTMLs files. However, using the mvc-flask the default becomes views. You can use the app/views directory to stores templates.

Tests

You can run the tests, executing the follow command:

$ make test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].