GithubHelp home page GithubHelp logo

jk9941 / crud_flask_mysql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lintangwisesa/crud_flask_mysql

0.0 1.0 0.0 8 KB

Basic CRUD with Python Flask & MySQL Database

Python 82.38% HTML 17.62%

crud_flask_mysql's Introduction

simplinnovation

Basic CRUD: Flask & MySQL

  1. Activate MySQL server:

    $ cd C:\Program Files\MySQL\MySQL Server 8.0\bin
    $ mysql.exe -u <username> -p<password>
    $ mysql -u <username> -p

    On my case:

    $ mysql.exe -u lintang -p12345
    $ mysql -u lintang -p   

  1. Create a database & table on MySQL. I'll use a database called "lin_flask" & a table called "users":

    mysql>  CREATE DATABASE lin_flask;
    mysql>  USE lin_flask;
    mysql>  CREATE TABLE users (
                id int auto_increment,
                name varchar(100) not null,
                age tinyint,
                primary key (id)
            );

  1. Clone this repo. Edit database.yaml file according to your database configuration, then install all the packages needed. In this project I'm using flask, flask_cors & flask_mysqldb:

    $ git clone https://github.com/LintangWisesa/CRUD_Flask_MySQL.git
    $ cd CRUD_Flask_MySQL

    Install dependencies:

    $ pip install flask flask_cors flask_mysqldb
    $ py -m pip install flask flask_cors flask_mysqldb

  1. Run the server file. Make sure your MySQL server is still running. Your application server will run locally at http://localhost:5000/ :
    $ py app.py
    $ python app.py
    $ python3 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 ๐Ÿ’Œ [email protected]

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

crud_flask_mysql's People

Contributors

lintangwisesa avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.