Best Flask open-source libraries and packages

CRUD_Flask_PostgreSQL

Basic CRUD with Python Flask & PostgreSQL Database
Updated 1 year ago

simplinnovation

Basic CRUD: Flask & PostgreSQL

  1. Activate PostgreSQL server:

    $ cd C:\Program Files\PostgreSQL\10\bin
    $ psql -U postgres
      Password for user postgres: <insert password here>

  1. Create a database on PostgreSQL, my database name is "lin_flask":

    postgres=#  CREATE DATABASE lin_flask;
    postgres=#  \l 
    postgres=#  \c lin_flask

  1. Create a "users" table on "lin_flask" database:

    lin_flask=#  CREATE TABLE users(
                 id SERIAL PRIMARY KEY,
                 name VARCHAR(255),
                 age VARCAR(255)
                 );
    lin_flask=#  \d

  1. Clone this repo. Insert your database URI to database.yaml file, then install all the packages needed. In this project I'm using flask, flask_cors, flask_mysqldb, Flask-SQLAlchemy & psycopg2:
    $ git clone https://github.com/LintangWisesa/CRUD_Flask_PostgreSQL.git
    $ cd CRUD_Flask_PostgreSQL
    $ pip install flask flask_cors Flask-SQLAlchemy psycopg2

  1. Run the server file. Make sure your PostgreSQL server is still running. Your application server will run locally at http://localhost:5000/ :
    $ python app.py

  1. Give a request to the server. You can use Postman app:

    See the opening screen (home.html)

    GET /

    Post a data to database:

    POST /data
    body request: {name:"x", age:"y"}

    Get all data & specific data by id:

    GET /data
    GET /data/{:id}

    Update a data by id:

    PUT /data/{:id}
    body request: {name:"x", age:"y"}

    Delete a data by id:

    DELETE /data/{:id}

  1. Enjoy your code! 😎👌

See also:

Lintang Wisesa 💌 lintangwisesa@ymail.com

Facebook | Twitter | Google+ | Youtube | :octocat: GitHub | Hackster