- Installing and configuring the Python3.6+flask+mysql database
- Download and install MySQL database
- Download and install Mysql-python middleware
- Pip Install Flask-sqlalchemy (Python's ORM Framework SQLAlchemy)
- MySQL CREATE database
- Database configuration Information config.py
- Build MySQL and App connections
- Create a user model
From flask import flaskfrom flask_sqlalchemy import sqlalchemyimport Configapp = Flask (__name__) App.config.from_object ( Config) db = SQLAlchemy (APP) class User (db). Model): __tablename__ = ' user ' id = db. Column (db. Integer,primary_key=true,autoincrement=true) username = db. Column (db. String (a), nullable=false) password = db. Column (db. String (a), Nullable=false) Db.create_all () @app. Route ('/') def hello_world (): return ' Hello world! ' if __name__ = = ' __main__ ': app.run ()
' Mysql+pymysql://root:@127.0.0.1:3306/mis_db?charset=utf8 ' = False
Connect to MySQL database and create user model