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 Dynaconf, Marshmallow, SQLAlchemy, Faker, PyMySQL, Pytest, etc... which are installed inside the virtual environment "env_flask".

Facundo Padilla 19 Jul 23, 2022
NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.

NO LONGER MAINTAINED This repository is no longer maintained due to lack of time. You might check out the fork https://github.com/mrevutskyi/flask-res

null 1k Jan 4, 2023
NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.

NO LONGER MAINTAINED This repository is no longer maintained due to lack of time. You might check out the fork https://github.com/mrevutskyi/flask-res

null 1k Jan 15, 2021
Daniel Vaz Gaspar 4k Jan 8, 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 8, 2022
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 484 Feb 3, 2021
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框架, 可以检查参数并自动生成API文档

null 162 Dec 26, 2022
A public API written in Python using the Flask web framework to determine the direction of a road sign using AI

python-public-API This repository is a public API for solving the problem of the final of the AIIJC competition. The task is to create an AI for the c

Lev 1 Nov 8, 2021
Trame let you weave various components and technologies into a Web Application solely written in Python.

Trame Trame aims to be a framework for building interactive applications using a web front-end in plain Python. Such applications can be used locally

Kitware, Inc. 85 Dec 29, 2022
Otter is framework for creating microservices in Flask like fassion using RPC communication via message queue.

Otter Framework for microservices. Overview Otter is framework for creating microservices in Flask like fassion using RPC communication via message qu

Volodymyr Biloshytskyi 4 Mar 23, 2022
A simple todo app using flask and sqlachemy

TODO app This is a simple TODO app made using Flask. Packages used: DoodleCSS Special thanks to Chris McCormick (@mccrmx) :) Flask Flask-SQLAlchemy Fl

Lenin 1 Dec 26, 2021
Distribution Analyser is a Web App that allows you to interactively explore continuous distributions from SciPy and fit distribution(s) to your data.

Distribution Analyser Distribution Analyser is a Web App that allows you to interactively explore continuous distributions from SciPy and fit distribu

Robert Dzudzar 46 Nov 8, 2022
Swagger/OpenAPI First framework for Python on top of Flask with automatic endpoint validation & OAuth2 support

Connexion Connexion is a framework that automagically handles HTTP requests based on OpenAPI Specification (formerly known as Swagger Spec) of your AP

Zalando SE 4.2k Jan 7, 2023
Fully featured framework for fast, easy and documented API development with Flask

Flask RestPlus IMPORTANT NOTICE: This project has been forked to Flask-RESTX and will be maintained by by the python-restx organization. Flask-RESTPlu

Axel H. 2.7k Jan 4, 2023
Swagger/OpenAPI First framework for Python on top of Flask with automatic endpoint validation & OAuth2 support

Connexion Connexion is a framework that automagically handles HTTP requests based on OpenAPI Specification (formerly known as Swagger Spec) of your AP

Zalando SE 3.5k Feb 17, 2021
Fully featured framework for fast, easy and documented API development with Flask

Flask RestPlus IMPORTANT NOTICE: This project has been forked to Flask-RESTX and will be maintained by by the python-restx organization. Flask-RESTPlu

Axel H. 2.5k Feb 17, 2021
A Flask API REST to access words' definition

A Flask API to access words' definitions

Pablo Emídio S.S 9 Jul 22, 2022
A boilerplate Flask API for a Fullstack Project with some additional packages and configuration prebuilt. ⚙

Flask Boilerplate to quickly get started with production grade flask application with some additional packages and configuration prebuilt.

Yasser Tahiri 32 Dec 24, 2022
APIFlask is a lightweight Python web API framework based on Flask and marshmallow-code projects

APIFlask APIFlask is a lightweight Python web API framework based on Flask and marshmallow-code projects. It's easy to use, highly customizable, ORM/O

Grey Li 705 Jan 4, 2023