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 micro web-framework using asyncio coroutines and chained middleware.

Growler master ' dev Growler is a web framework built atop asyncio, the asynchronous library described in PEP 3156 and added to the standard library i

687 Nov 27, 2022
cirrina is an opinionated asynchronous web framework based on aiohttp

cirrina cirrina is an opinionated asynchronous web framework based on aiohttp. Features: HTTP Server Websocket Server JSON RPC Server Shared sessions

André Roth 32 Mar 05, 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 04, 2023
🔥 Fire up your API with this flamethrower

🔥 Fire up your API. Documentation: https://flama.perdy.io Flama Flama aims to bring a layer on top of Starlette to provide an easy to learn and fast

José Antonio Perdiguero 216 Dec 26, 2022
A proof-of-concept CherryPy inspired Python micro framework

Varmkorv Varmkorv is a CherryPy inspired micro framework using Werkzeug. This is just a proof of concept. You are free to use it if you like, or find

Magnus Karlsson 1 Nov 22, 2021
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
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
The Modern And Developer Centric Python Web Framework. Be sure to read the documentation and join the Slack channel questions: http://slack.masoniteproject.com

NOTE: Masonite 2.3 is no longer compatible with the masonite-cli tool. Please uninstall that by running pip uninstall masonite-cli. If you do not unin

Masonite 1.9k Jan 04, 2023
The comprehensive WSGI web application library.

Werkzeug werkzeug German noun: "tool". Etymology: werk ("work"), zeug ("stuff") Werkzeug is a comprehensive WSGI web application library. It began as

The Pallets Projects 6.2k Jan 01, 2023
Goblet is an easy-to-use framework that enables developers to quickly spin up fully featured REST APIs with python on GCP

GOBLET Goblet is a framework for writing serverless rest apis in python in google cloud. It allows you to quickly create and deploy python apis backed

Austen 78 Dec 27, 2022
An alternative serializer implementation for REST framework written in cython built for speed.

drf-turbo An alternative serializer implementation for REST framework written in cython built for speed. Free software: MIT license Documentation: htt

Mng 74 Dec 30, 2022
Pulumi-checkly - Checkly Pulumi Provider With Python

🚨 This project is still in very early stages and is not stable, use at your own

Checkly 16 Dec 15, 2022
The Python micro framework for building web applications.

Flask Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to co

The Pallets Projects 61.5k Jan 06, 2023
Fast, asynchronous and elegant Python web framework.

Warning: This project is being completely re-written. If you're curious about the progress, reach me on Slack. Vibora is a fast, asynchronous and eleg

vibora.io 5.7k Jan 08, 2023
🦍 The Cloud-Native API Gateway

Kong or Kong API Gateway is a cloud-native, platform-agnostic, scalable API Gateway distinguished for its high performance and extensibility via plugi

Kong 33.8k Jan 09, 2023
Free and open source full-stack enterprise framework for agile development of secure database-driven web-based applications, written and programmable in Python.

Readme web2py is a free open source full-stack framework for rapid development of fast, scalable, secure and portable database-driven web-based applic

2k Dec 31, 2022
Pretty tornado wrapper for making lightweight REST API services

CleanAPI Pretty tornado wrapper for making lightweight REST API services Installation: pip install cleanapi Example: Project folders structure: . ├──

Vladimir Kirievskiy 26 Sep 11, 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
The core of a service layer that integrates with the Pyramid Web Framework.

pyramid_services The core of a service layer that integrates with the Pyramid Web Framework. pyramid_services defines a pattern and helper methods for

Michael Merickel 78 Apr 15, 2022
Containers And REST APIs Workshop

Containers & REST APIs Workshop Containers vs Virtual Machines Ferramentas Podman: https://podman.io/ Docker: https://www.docker.com/ IBM CLI: https:/

Vanderlei Munhoz 8 Dec 16, 2021