- 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
' mysql+pymysql://root: @localhost: 3306/mis_db?charset=utf8 ' = False
- establish MySQL and app connections
from flask import flask,render_template from flask_sqlalchemy import SQLAlchemy import Configapp = Flask (__name__ ) # Initializes a flask object that needs to pass a parameter __name__ app.config.from_object ( Config) db =sqlalchemy (APP) Db.create_all ()
- Create a user model
#/Create the User model class "user" (db). Model): __tablename__ = ' user ' id=db. Column (db. integer,primare_key=taberror,autoincrement=True) username=db. Column (db. String (a), nullable=False) password=db. Colum (db. String (), nullable=False)
Connect to MySQL database and create user model