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
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
Light, Flexible and Extensible ASGI API framework

Starlite Starlite is a light, opinionated and flexible ASGI API framework built on top of pydantic and Starlette. Check out the Starlite documentation

Na'aman Hirschfeld 1.6k Jan 09, 2023
Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine

Flask-Potion Description Flask-Potion is a powerful Flask extension for building RESTful JSON APIs. Potion features include validation, model resource

DTU Biosustain 491 Dec 08, 2022
Lemon is an async and lightweight API framework for python

Lemon is an async and lightweight API framework for python . Inspired by Koa and Sanic .

Joway 29 Nov 20, 2022
Pyrin is an application framework built on top of Flask micro-framework to make life easier for developers who want to develop an enterprise application using Flask

Pyrin A rich, fast, performant and easy to use application framework to build apps using Flask on top of it. Pyrin is an application framework built o

Mohamad Nobakht 10 Jan 25, 2022
WebSocket and WAMP in Python for Twisted and asyncio

Autobahn|Python WebSocket & WAMP for Python on Twisted and asyncio. Quick Links: Source Code - Documentation - WebSocket Examples - WAMP Examples Comm

Crossbar.io 2.4k Jan 06, 2023
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
Flask like web framework for AWS Lambda

lambdarest Python routing mini-framework for AWS Lambda with optional JSON-schema validation. ⚠️ A user study is currently happening here, and your op

sloev / Johannes Valbjørn 91 Nov 10, 2022
You can use the mvc pattern in your flask application using this extension.

You can use the mvc pattern in your flask application using this extension. Installation Run the follow command to install mvc_flask: $ pip install mv

Marcus Pereira 37 Dec 17, 2022
Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints.

Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints. check parameters and generate API documents automatically. Flask Sugar是一个基于flask,pyddantic,类型注解的API框架

162 Dec 26, 2022
Mini Web Framework on MicroPython (Esp8266)

dupgee Dupgee is a mini web framework developed for micro-python(Tested on esp8266). Installation pip install dupgee Create Project dupgee create newp

ahmet kotan 38 Jul 25, 2022
A simple Tornado based framework designed to accelerate web service development

Toto Toto is a small framework intended to accelerate web service development. It is built on top of Tornado and can currently use MySQL, MongoDB, Pos

Jeremy Olmsted-Thompson 61 Apr 06, 2022
A high-level framework for building GitHub applications in Python.

A high-level framework for building GitHub applications in Python. Core Features Async Proper ratelimit handling Handles interactions for you (

Vish M 3 Apr 12, 2022
Daniel Vaz Gaspar 4k Jan 08, 2023
A tool for quickly creating REST/HATEOAS/Hypermedia APIs in python

ripozo Ripozo is a tool for building RESTful/HATEOAS/Hypermedia apis. It provides strong, simple, and fully qualified linking between resources, the a

Vertical Knowledge 198 Jan 07, 2023
Bablyon 🐍 A small ASGI web framework

A small ASGI web framework that you can make asynchronous web applications using uvicorn with using few lines of code

xArty 8 Dec 07, 2021
O SnakeG é um WSGI feito para suprir necessidadades de perfomance e segurança.

SnakeG O SnakeG é um WSGI feito para suprir necessidadades de perfomance e segurança. Veja o que o SnakeG possui: Multiprocessamento de requisições HT

Jaedson Silva 1 Jul 02, 2022
A library that makes consuming a RESTful API easier and more convenient

Slumber is a Python library that provides a convenient yet powerful object-oriented interface to ReSTful APIs. It acts as a wrapper around the excellent requests library and abstracts away the handli

Sam Giles 597 Dec 13, 2022
Asita is a web application framework for python based on express-js framework.

Asita is a web application framework for python. It is designed to be easy to use and be more easy for javascript users to use python frameworks because it is based on express-js framework.

Mattéo 4 Nov 16, 2021
FPS, fast pluggable server, is a framework designed to compose and run a web-server based on plugins.

FPS, fast pluggable server, is a framework designed to compose and run a web-server based on plugins. It is based on top of fastAPI, uvicorn, typer, and pluggy.

Adrien Delsalle 1 Nov 16, 2021