- 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 fromFlaskImportrender_template 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) Db.create_all ()
@app. Route ('/')defHello_world ():returnRender_template ('base.html') @app. Route ('/login')deflogin ():returnRender_template ('login.html') @app. Route ('/regist')defregist ():returnRender_template ('regist.html') @app. Route ('/fabu')defFabu ():returnRender_template ('fabu.html')if __name__=='__main__': App.run (Debug=true)
' mysql+pymysql://root: @localhost: 3306/mis_db?charset=utf8 ' = False
Connect to MySQL database and create user model