- 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
fromFlaskImportFlask fromFlask_sqlalchemyImportSQLAlchemyImportConfigapp= Flask (__name__) App.config.from_object (config) DB=SQLAlchemy (APP)classUser (db. Model):__tablename__='User'ID=db. Column (db. Integer,primary_key=true,autoincrement=True) Username=db. Column (db. String (nullable=),False) Password= db. Column (db. String (nullable=),False) Nickname= db. Column (db. String (nullable=),False) Db.create_all () @app. Route ('/')defHello_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