GithubHelp home page GithubHelp logo

liuyuweitarek / flask_mysql_quicktemplate Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 324 KB

This is a quick template which help you build up backend with Flask + MySQL and handle config and API functions clearly.

License: MIT License

Python 100.00%
flask mysql python

flask_mysql_quicktemplate's Introduction

Flask_MySQL_QuickTemplate

This is a quick template which help you build up backend with Flask + MySQL and handle config and API functions clearly.

Installation

  1. Clone the project

    $ git clone https://github.com/liuyuweitarek/Flask_MySQL_QuickTemplate.git
    $ cd Flask_MySQL_QuickTemplate
  2. Build Project Python Environment

    Python Version > 3

    • Set up/Start up virtual env
      $ python3 -m venv env
      $ source env/bin/activate
    • Install Dependencies
      $ python -m pip install --upgrade pip
      $ pip install -r requirements.txt 
  3. Set up MySQL Environment

    • MySQL Installation Guideline: Follow the instructions based on your OS system.

    • Create the database for this project

       $ mysql -u root -p
         (input password)
       $ mysql> CREATE DATABASE {DATABASENAME}_dev ;
       $ mysql> CREATE DATABASE {DATABASENAME}_prod ;

      If you are not root, you could ask your admin for creating databases and granting the privileges to you with adding the commands below.

       (In root account)
       $ mysql> GRANT ALL PRIVILEGES ON {DATABASENAME}_dev.* TO '{ACCOUNT}'@'%';
       $ mysql> GRANT ALL PRIVILEGES ON {DATABASENAME}_prod.* TO '{ACCOUNT}'@'%';

      P.S. If the error shows that it can't find the user, using the code down below to check your account identity

       $ SELECT User FROM mysql.user;
       
       # It shows like:
       +------------------+--------------+--------------+
       | user             | host         | password     |
       +------------------+--------------+--------------+
       | {ACCOUNT}        | localhost    | 37as%#8123fs |
       | Other_user       | %            | slclk2j393   |
       +------------------+--------------+--------------+
       1 rows in set (0.01 sec)

      Based on the columns, "user" and "host", on User table, you might need to change the commands to :

       (In root account)
       $ mysql> GRANT ALL PRIVILEGES ON {DATABASENAME}_dev.* TO '{ACCOUNT}'@'localhost';
       $ mysql> GRANT ALL PRIVILEGES ON {DATABASENAME}_prod.* TO '{ACCOUNT}'@'localhost';
  4. Modify cfg.py's config

    class ProductionConfig:
      ...
      HOST = {YOUR IP ADDRESS}                                                              <= Edit              
      PORT = {PORT which is available on your machine}                                      <= Edit
      ...
    
      # SQL
      SQLALCHEMY_DATABASE_URI= "mysql://{ACCOUNT}:{PASSWORD}@127.0.0.1/{DATABASENAME}_prod" <= Edit
      ...
    
    class DevelopmentConfig:
      ...
      HOST = {YOUR IP ADDRESS}                                                              <= Edit
      PORT = {PORT which is available on your machine}                                      <= Edit
      ...
    
      # SQL
      SQLALCHEMY_DATABASE_URI= "mysql://{ACCOUNT}:{PASSWORD}@127.0.0.1/{DATABASE_NAME}_dev" <= Edit
      ...

Usage

  1. Make sure that MySQL Service active correctly
    $ service mysql status

  2. Activate project python environment
    $ cd ~/Flask_MySQL_QuickTemplate
    $ source env/bin/activate
    $ export PYTHONPATH=src
  3. Run
     $ python run.py --config [dev, prod]

Test

[ GET API ] : {YOUR_IP_ADDRESS}:{PORT}/GET/dev_or_prod

[ POST API ] : {YOUR_IP_ADDRESS}:{PORT}/POST/storedata

flask_mysql_quicktemplate's People

Contributors

liuyuweitarek avatar

Watchers

 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.