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

Overview

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

Comments
  • jinja2.exceptions.TemplateNotFound: index.html

    jinja2.exceptions.TemplateNotFound: index.html

    Hi I cloned your code and while trying to use the example app I am getting this error

    raise TemplateNotFound(template)
    

    jinja2.exceptions.TemplateNotFound: index.html

    I tried creating a templates folder under the example directory and copied contents from the view folder to it. still the same error

    Appreciate your help

    bug question 
    opened by bjenmonk 8
  • FlaskMVC reinitialize app.template_folder and drop value settings in Flask initialize

    FlaskMVC reinitialize app.template_folder and drop value settings in Flask initialize

    This is cool mvc implementation, especially for me.

    When i deep to Flask, i found the mvc-flask. It so like for me, because i'd RoR programmer. So, i have to implement my folder structure identical to rails application. But i found two incompatibilities with Ruby on Rails.

    1. I can't set folder for templates, when initialize Flask:
    app = Flask(self.__name, template_folder = './app/views')
    ...
    FlaskMVC(app, path = 'app')
    

    After that, Flask searches templates in ./views folder, but not in ./app/views as i want. So, i try to propose pull-request to fix this behaviour. With best regards to maintainers. FlaskMVC making python better (for me, for example).

    question 
    opened by bsa7 1
  • NameError: name 'view' is not defined

    NameError: name 'view' is not defined

    Hi, I have recently started working with mvc-flask, however, I unfortunately cannot seem to get view() to work. (view is undefined)

    app/routes.py

    from mvc_flask import Router
    
    Router.get("/", "landing#route")
    

    app/controllers/landing_controller.py

    from flask import session
    
    class LandingController:
        def route(self):
            return view("index.html")
    

    app.py

    from flask import Flask
    from mvc_flask import FlaskMVC
    
    app = Flask(__name__)
    FlaskMVC(app)
    
    doc question 
    opened by fzorb 1
  • do we improve routes using yml?

    do we improve routes using yml?

    What do you think about changing the definition of routes from json to yaml?

    Something like:

    routes:
      home:
        index
      
      books:
        new:
          path: /
        create:
          path: /create
          method: post
      
      posts:
        models: true
        only:
          - show
          - new
          - create
      
      users:
        index:
          hooks:
            before_request: "required"
    

    if the user define model: true the mvc-flask automatically will be create the follows routes:

    - index (/)
    - show (/show/:id)
    - new (/new)
    - create (/create)
    - edit (/edit/:id)
    - update (/)
    - delete (/delete/:id)
    

    But, you can use the only parameter to regular this.

    enhancement question 
    opened by marcuxyz 1
  • [CI/CD] change requirements.txt to poetry

    [CI/CD] change requirements.txt to poetry

    Currently, we use pip install requirements.txt inside GitHub action to install all dependencies on the project. We should support poetry directly instead of export the requirements files.

    opened by marcuxyz 1
  • Sent to data through form[method=put]

    Sent to data through form[method=put]

    Problem

    The HTML default not work with put and delete. Then... We need sent the form data to receive in update route. Recently not sent, because need javascript called.

    Solution

    Create javascript helper that will be called every time that the request form has been sent

    Comments

    We need follow the solutions of greats frameworks, as: Laravel, Rails and etc.

    Screenshot 2022-10-31 at 16 20 30 enhancement 
    opened by marcuxyz 0
  • create namespace or group method

    create namespace or group method

    Recently we have not group defined to routes, the routes can work as prefix-url of many routes. I haven't thought of a definitive model, but, it can be:

    g = Router.namespace("/tasks") 
    
    # or
    
    g = Router.group("/tasks")
    
    g.get("/", "tasks#index")  # you can access: https://.../tasks/
    
    opened by marcuxyz 0
  • action could receive view and request object

    action could receive view and request object

    currently we have import render_template function to use templates and request to accomplish operation based in visitord request.

    Would cool if these objects was available. e.g:

    class HomeController:
        def index(self, view, request):
            return view("index.html")
    
    enhancement 
    opened by marcuxyz 0
  • create  al method to register all routes

    create al method to register all routes

    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 control 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"]

    close #16

    enhancement 
    opened by marcuxyz 0
  • update mvc_flask to 2.0.0

    update mvc_flask to 2.0.0

    This verion contain break change:

    • Now the routes are be registered using .py file.
    • To standardize the application the mvc_flask extension just work with app directory
    • You can register routes based in methods: GET, POST, UPDATE and DELETE
    • we no longer support to routes.json file.

    To register routes you can use the routes.py inside app directory and the file must contain the import Router object, The Router object must be used to register the routes. You can use GET, POST, UPDATE and DELETE methods to register routes. E.g:

    from mvc_flask import Router
    
    Router.get("/", "home#index")
    Router.get("/hello", "home#hello")
    Router.post("/messages", "messages#create")
    Router.put("/users/<id>", "users#update")
    Router.delete("/users/<id>", "users#delete")
    
    opened by marcuxyz 0
  • Refactory FlaskMVC class

    Refactory FlaskMVC class

    It would be nice if we could refactor the FlaskMVC class including the blueprint calls to create the new routes.

    This will make it easier to call hooks, such as:

    • before_requests
    • after_requests

    and etc. Related by issue #10

    refactory 
    opened by marcuxyz 0
  • Create CLI commands for mvc

    Create CLI commands for mvc

    For enhancement the extensions, we could create commands for generate controllers and etc. E.g:

    flask generate controller home

    The command must generate file:

    app
    ├── controllers
    │   └── home_controller.py
    
    enhancement 
    opened by marcuxyz 0
Releases(2.6.0)
  • 2.4.0(Aug 8, 2022)

    • Include patch HTTP verb in update route.
    • Parameters ~~view~~, ~~request~~ has been removed
    class HomeController:
        def index(self, view, request):
            return view("index.html")
    

    Now, you can import render_template and request directly of flask package.

    from flask import render_template
    
    class HomeController:
        def index(self):
            return render_template("index.html")
    
    • Enhancement of unit tests
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Nov 11, 2021)

    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"]

    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Nov 1, 2021)

    This verion contain break change:

    • Now the routes are be registered using .py file.
    • To standardize the application the mvc_flask extension just work with app directory
    • You can register routes based in methods: GET, POST, UPDATE and DELETE
    • we no longer support to routes.json file.

    To register routes you can use the routes.py inside app directory and the file must contain the import Router object, The Router object must be used to register the routes. You can use GET, POST, UPDATE and DELETE methods to register routes. E.g:

    from mvc_flask import Router
    
    Router.get("/", "home#index")
    Router.get("/hello", "home#hello")
    Router.post("/messages", "messages#create")
    Router.put("/users/<id>", "users#update")
    Router.delete("/users/<id>", "users#delete")
    
    Source code(tar.gz)
    Source code(zip)
Owner
Marcus Pereira
Cristão, amante de jogos eletrônicos e desenvolvimento de software.
Marcus Pereira
Flask + Docker + Nginx + Gunicorn + MySQL + Factory Method Pattern

This Flask project is reusable and also an example of how to merge Flask, Docker, Nginx, Gunicorn, MySQL, new: Flask-RESTX, Factory Method design pattern, and other optional dependencies such as Dyna

Facundo Padilla 19 Jul 23, 2022
TinyAPI - 🔹 A fast & easy and lightweight WSGI Framework for Python

TinyAPI - 🔹 A fast & easy and lightweight WSGI Framework for Python

xArty 3 Apr 08, 2022
WAZO REST API for the call management of the C4 infrastructure

wazo-router-calld wazo-router-calld provides REST API for the C4 infrastructure. Installing wazo-router-calld The server is already provided as a part

Wazo Platform 4 Dec 21, 2022
PipeLayer is a lightweight Python pipeline framework

PipeLayer is a lightweight Python pipeline framework. Define a series of steps, and chain them together to create modular applications

greaterthan 64 Jul 21, 2022
A PC remote controller for YouTube and Twitch

Lazynite Lazynite is a PC remote controller for YouTube and Twitch on Telegram. Features Volume control; Browser fullscreen / video fullscreen; PC shu

Alessio Celentano 46 Nov 12, 2022
A familiar HTTP Service Framework for Python.

Responder: a familiar HTTP Service Framework for Python Powered by Starlette. That async declaration is optional. View documentation. This gets you a

Taoufik 3.6k Dec 27, 2022
Daniel Vaz Gaspar 4k Jan 08, 2023
Online Boutique is a cloud-native microservices demo application

Online Boutique is a cloud-native microservices demo application. Online Boutique consists of a 10-tier microservices application. The application is

Matt Reider 1 Oct 22, 2021
A shopping list and kitchen inventory management app.

Flask React Project This is the backend for the Flask React project. Getting started Clone this repository (only this branch) git clone https://github

11 Jun 03, 2022
Embrace the APIs of the future. Hug aims to make developing APIs as simple as possible, but no simpler.

Read Latest Documentation - Browse GitHub Code Repository hug aims to make developing Python driven APIs as simple as possible, but no simpler. As a r

Hug API Framework 6.7k Dec 27, 2022
Library for building WebSocket servers and clients in Python

What is websockets? websockets is a library for building WebSocket servers and clients in Python with a focus on correctness and simplicity. Built on

Aymeric Augustin 4.3k Dec 31, 2022
Asynchronous HTTP client/server framework for asyncio and Python

Async http client/server framework Key Features Supports both client and server side of HTTP protocol. Supports both client and server Web-Sockets out

aio-libs 13.2k Jan 05, 2023
Official mirror of https://gitlab.com/pgjones/quart

Quart Quart is an async Python web microframework. Using Quart you can, render and serve HTML templates, write (RESTful) JSON APIs, serve WebSockets,

Phil Jones 2 Oct 05, 2022
Loan qualifier app - Loan Qualifier Application Built With Python

Loan Qualifier Application This program is designed to automate the discovery pr

Phil Hills 1 Jan 04, 2022
REST API framework designed for human beings

Eve Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully f

eve 6.6k Jan 07, 2023
Appier is an object-oriented Python web framework built for super fast app development.

Joyful Python Web App development Appier is an object-oriented Python web framework built for super fast app development. It's as lightweight as possi

Hive Solutions 122 Dec 22, 2022
An abstract and extensible framework in python for building client SDKs and CLI tools for a RESTful API.

django-rest-client An abstract and extensible framework in python for building client SDKs and CLI tools for a RESTful API. Suitable for APIs made wit

Certego 4 Aug 25, 2022
News search API developed for the purposes of the ColdCase Project.

Saxion - Cold Case - News Search API Setup Local – Linux/MacOS Make sure you have python 3.9 and pip 21 installed. This project uses a MySQL database,

Dimitar Rangelov 3 Jul 01, 2021
Endpoints is a lightweight REST api framework written in python and used in multiple production systems that handle millions of requests daily.

Endpoints Quickest API builder in the West! Endpoints is a lightweight REST api framework written in python and used in multiple production systems th

Jay Marcyes 30 Mar 05, 2022
Bromelia-hss implements an HSS by using the Python micro framework Bromélia.

Bromélia HSS bromelia-hss is the second official implementation of a Diameter-based protocol application by using the Python micro framework Bromélia.

henriquemr 7 Nov 02, 2022